Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy_loader.attach_stub confuses submodule and function of the same name #54

Open
lagru opened this issue Jun 13, 2023 · 4 comments
Open

Comments

@lagru
Copy link
Member

lagru commented Jun 13, 2023

At scikit-image, we are seeing that if a submodule and lazy loaded function have the same name, the module is unexpectedly imported instead. This behavior in the case of rolling_ball can be seen in scikit-image/scikit-image#7021, scikit-image/scikit-image@079962f, failing CI example.

What I find confusing that this does not happen for all jobs, though I haven't figured out a common denominator between the passing and failing group respectively. 🤔

Our approach has been to rename the submodule but this may hint at a deeper issue / limitation / quirk in lazy_loader?

@lagru
Copy link
Member Author

lagru commented Jun 13, 2023

You even check for this case in https://github.com/scientific-python/lazy_loader/blob/a6188ac0a4dee20edc6fab099e606b19148de0d4/lazy_loader/__init__.py#L79-L84

Unfortunately I can't reproduce this locally yet to check what is going wrong...

@stefanv
Copy link
Member

stefanv commented Jan 25, 2024

I suspect this is the following documented issue: https://scientific-python.org/specs/spec-0001/#caveats

@stefanv
Copy link
Member

stefanv commented Mar 15, 2024

@lagru Did this happen inside of a doctest? The logs are unfortunately no longer accessible for me to check.

@lagru
Copy link
Member Author

lagru commented Mar 16, 2024

Yeah, we are in luck. Building and testing scikit-image/scikit-image@079962f still works with the current dev environment. I changed the name of back to rolling_ball.py and reproduce the error with spin test -- --doctest-modulesskimage/restoration/rolling_ball.py

_______________________ [doctest] skimage.restoration.rolling_ball.rolling_ball _______________________
059     .. [1] Sternberg, Stanley R. "Biomedical image processing." Computer 1
060            (1983): 22-34. :DOI:`10.1109/MC.1983.1654163`
061
062     Examples
063     --------
064     >>> import numpy as np
065     >>> from skimage import data
066     >>> from skimage.restoration import rolling_ball
067     >>> image = data.coins()
068     >>> background = rolling_ball(data.coins())
UNEXPECTED EXCEPTION: TypeError("'module' object is not callable")
Traceback (most recent call last):
File "~/.local/lib/micromamba/envs/skidev312/lib/python3.12/doctest.py", line 1357, in __run
exec(compile(example.source, filename, "single",
File "<doctest skimage.restoration.rolling_ball.rolling_ball[4]>", line 1, in <module>
TypeError: 'module' object is not callable
~/Res/scikit-image/skimage/restoration/rolling_ball.py:68: UnexpectedException

Can also be reproduced on current main after renaming back to rolling_ball.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants