Skip to content

Lazy Packages Fail to Maintain Lazy Submodule Context Post-Load #15

@matthewphsmith

Description

@matthewphsmith

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://github.com/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://github.com/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions