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

Error occurs when parent modules are previously imported #2

Closed
spacebuoy opened this issue Jan 20, 2018 · 4 comments
Closed

Error occurs when parent modules are previously imported #2

spacebuoy opened this issue Jan 20, 2018 · 4 comments

Comments

@spacebuoy
Copy link

spacebuoy commented Jan 20, 2018

This first occurred in my modules but the error also occurs with python email module. The error occurs when email is system imported before lazy_module('email.mime') or lazy_module('email.mime.audio') or email.mime is imported before lazy_module('email.mime.audio').

Ceti$ py
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

from lazy_import import lazy_module
import sys
'email' in sys.modules
False
lazy_module('email.mime.audio') # This works
^D

Ceti$ py
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

from lazy_import import lazy_module
import email
import sys
'email' in sys.modules
True
lazy_module('email.mime.audio') # This fails first time, works on second call
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/lazy_import/init.py", line 302, in lazy_module
mod = _lazy_module(modname, error_strings, lazy_mod_class)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/lazy_import/init.py", line 354, in _lazy_module
super(LazyModule, mod).setattr(submodname, submod)
TypeError: super(type, obj): obj must be an instance or subtype of type

@mnmelo mnmelo closed this as completed in 0c66e99 Jan 22, 2018
@mnmelo
Copy link
Owner

mnmelo commented Jan 22, 2018

Confirmed this was creeping up when lazy-loading submodules of fully-loaded base modules. Fix was simple, but since this has serious impact I released v0.2.2 with it right away.

@spacebuoy
Copy link
Author

Fixed! Great to get the quick turnaround. All is working well.

@spacebuoy
Copy link
Author

I think I'm following the directions but I am encountering an error with this command
obj = lazy_callable('cmd.Cmd')
Adding "import cmd" before the above command avoids the error.
Does the cmd module need to be imported beforehand?

@mnmelo
Copy link
Owner

mnmelo commented Jan 22, 2018

Could you open a new issue with the question, and the exact lines you're using? On a first check I can run that without problems.

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