diff options
author | Brett Cannon <brett@python.org> | 2013-03-13 17:41:36 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-03-13 17:41:36 (GMT) |
commit | 4802becb160d76c2e0993ce7e8abbbe23667f91f (patch) | |
tree | 47c56787e702b1b15bc2d3fee5de3e9730aa9a57 /Lib/importlib | |
parent | aa73a1c9c9c149002f98dbf6fdd12eb3d41225ee (diff) | |
download | cpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.zip cpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.tar.gz cpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.tar.bz2 |
Issue #17117: Have both import itself and importlib.util.set_loader()
set __loader__ on a module when set to None.
Thanks to Gökcen Eraslan for the fix.
Diffstat (limited to 'Lib/importlib')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index c471b2f..73aa0ca 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -494,7 +494,7 @@ def set_loader(fxn): """Set __loader__ on the returned module.""" def set_loader_wrapper(self, *args, **kwargs): module = fxn(self, *args, **kwargs) - if not hasattr(module, '__loader__'): + if getattr(module, '__loader__', None) is None: module.__loader__ = self return module _wrap(set_loader_wrapper, fxn) @@ -875,12 +875,9 @@ class _LoaderBasics: module.__cached__ = module.__file__ else: module.__cached__ = module.__file__ - module.__package__ = name if self.is_package(name): module.__path__ = [_path_split(module.__file__)[0]] - else: - module.__package__ = module.__package__.rpartition('.')[0] - module.__loader__ = self + # __package__ and __loader set by @module_for_loader. _call_with_frames_removed(exec, code_object, module.__dict__) return module @@ -1551,7 +1548,7 @@ def _find_and_load_unlocked(name, import_): except AttributeError: pass # Set loader if need be. - if not hasattr(module, '__loader__'): + if getattr(module, '__loader__', None) is None: try: module.__loader__ = loader except AttributeError: |