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 Packages Fail to Maintain Lazy Submodule Context Post-Load #15

Open
matthewphsmith opened this issue Jul 29, 2019 · 1 comment
Open

Comments

@matthewphsmith
Copy link

Two issues I am seeing in Python 2.7:

  1. Only the first lazy submodule will appear in a package shared by two lazy submodules.
la = lazy_import.lazy_module('package.a')
lb = lazy_import.lazy_module('package.b')

import package
'a' in type(package)._lazy_import_submodules
'b' not in type(package)._lazy_import_submodules

This is because when a cached lazy package is found (https:/mnmelo/lazy_import/blob/master/lazy_import/__init__.py#L378), we don't update the reference of _LazyModule to the cached module and hence the module from the last iteration of the loop has it's _lazy_import_submodules attribute updated. Thus resulting in the following:

'b' in type(lb)._lazy_import_submodules
  1. After a package is loaded, references to lazy modules are lost, resulting in:
la = lazy_import.lazy_module('package.a')

import package
package.a == la
from package import a  !!!! fails !!!!

This problem is rooted here: https:/mnmelo/lazy_import/blob/master/lazy_import/__init__.py#L689

The issue is that prior to reloading the module, we clean all lazy sub-module attributes and LazyModule class attributes. We then try to restore those attributes, but we rely on a class attribute which has been removed. Thus no sub-modules are found and the lazy state isn't restored.

@matthewphsmith
Copy link
Author

Proposed fix: #14

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

1 participant