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

Allow outside-module imports in lazy_loader.attach_stub #52

Open
lagru opened this issue Jun 7, 2023 · 3 comments
Open

Allow outside-module imports in lazy_loader.attach_stub #52

lagru opened this issue Jun 7, 2023 · 3 comments
Labels
type: Enhancement New feature or request

Comments

@lagru
Copy link
Member

lagru commented Jun 7, 2023

In scikit-image/scikit-image#7007 we have run into https://github.com/scientific-python/lazy_loader/blob/2334bd279d40e0dadd3af48fe4ec494d3ce7f47d/lazy_loader/__init__.py#L204-L206

while trying to apply lazy_loader.attach_stub to skimage.morphology. That submodule tries to import and expose label from skimage.measure again as a public API function. We can workaround this by just making this import one level-deeper in a submodule, e.g. skimage.morphology._util.

However, I was wondering if this limitation is artificial and could be removed or if this constraint prevents other problems for lazy_loader.

@stefanv
Copy link
Member

stefanv commented Jun 7, 2023

/cc @tlambert03

@tlambert03
Copy link
Contributor

if I recall correctly, that limitation was more like a NotImplementedError...
I do think you'd run into NameErrors if you just naively removed the ValueError, but i think it's something that could be implemented with a little work (need to reorient myself to how that Visitor was working). I'll try to take a look soon

@tlambert03
Copy link
Contributor

ok, now I remember, this "within-module" limitation is actually hardcoded into the attach function itself (not just the stub loader).

https://github.com/scientific-python/lazy_loader/blob/2334bd279d40e0dadd3af48fe4ec494d3ce7f47d/lazy_loader/__init__.py#L71-L77

The lines above limit lazy_loader.attach to modules that are below whatever module attach is being used in. So, if the stub loader is to support super-module imports, the attach function would also need to be updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants