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

Keep reference to original module in LazyLoadModule #439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pymel/util/utilitytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,14 @@ def __init__(self, name, contents, autoSubClass=True):
types.ModuleType.__init__(self, name)
self.__dict__.update(contents)
self._lazyGlobals = contents # globals of original module
# keep a reference to the original module so all values in its __dict__
# are not set to None by the module destructor when sys.modules[name] is
# the last reference to it and is replaced below, this prevents any
# problems where another reference to the original module exists (such
# as in a PEP-302 loader)
self._lazyModule = sys.modules.get(name)
# add ourselves to sys.modules, overwriting the original module
sys.modules[name] = self
# the above line assigns a None value to all entries in the original globals.
# luckily, we have a copy on this module we can use to restore it.
self._lazyGlobals.update(self.__dict__)

def __dir__(self):
# for modules, dir usually only returns what's in the dict, and does
Expand Down