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_module breaks built-in modules #4

Open
blyxxyz opened this issue Jan 26, 2018 · 5 comments
Open

lazy_module breaks built-in modules #4

blyxxyz opened this issue Jan 26, 2018 · 5 comments

Comments

@blyxxyz
Copy link

blyxxyz commented Jan 26, 2018

lazy_module breaks built-in modules (i.e. modules listed in sys.builtin_module_names) that haven't been loaded yet:

>>> import lazy_import
>>> math = lazy_import.lazy_module('math')
>>> math.log
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ring/.local/lib/python3.6/site-packages/lazy_import/__init__.py", line 157, in __getattribute__
    return super(LazyModule, self).__getattribute__(attr)
AttributeError: module 'math' has no attribute 'log'

The same happens, for example, with zlib and pwd (but not with sys, because it's already loaded).

@mnmelo
Copy link
Owner

mnmelo commented Jan 26, 2018

Thanks for this heads up.
I can confirm this occurs in python 3.6 but, interestingly, not in 2.7. It is boiling down to what is actually performed by the module reloading, and I suspect some internal is cutting corners in python 3 if it sees it's a builtin. I'll be looking into it.

@spacebuoy
Copy link

I can duplicate this error. I use ipython which imports many packages so I was not seeing this error and it does not occur with the cmd module I've been using, in case this helps:

cmd = lazy_import.lazy_module('cmd')
cmd
Lazily-loaded module cmd
cmd.Cmd
<class 'cmd.Cmd'>
cmd
<module 'cmd' from '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/cmd.py'>

@mnmelo
Copy link
Owner

mnmelo commented Feb 5, 2018

Ok, after some research I can see this is triggered not because those are builtins but because they are C-extensions. I can trigger the faulty behavior with a non builtin C-extension.

Trying to figure how I can tell the reloader to behave properly in these cases...

@jonas-eschle
Copy link

Are there any news on that?

@danlkv
Copy link

danlkv commented Oct 9, 2020

@mnmelo any updates? This would be very useful if it worked on my cpp extension module....

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

5 participants