diff Lib/importlib/_bootstrap.py @ 84169:ebec625b13f9

Issues #18058, 18057: Make importlib._bootstrap.NamespaceLoader conform the the InspectLoader ABC. Perk of this is that runpy/-m can now work with namespace packages.
author Brett Cannon <brett@python.org>
date Sun, 16 Jun 2013 14:56:58 -0400
parents 9cacdb9d0c59
children 205aa49e5cd5
line wrap: on
line diff
--- a/Lib/importlib/_bootstrap.py	Sun Jun 16 13:14:06 2013 -0400
+++ b/Lib/importlib/_bootstrap.py	Sun Jun 16 14:56:58 2013 -0400
@@ -1238,12 +1238,25 @@
     def module_repr(cls, module):
         return "<module '{}' (namespace)>".format(module.__name__)
 
+    def is_package(self, fullname):
+        return True
+
+    def get_source(self, fullname):
+        return ''
+
+    def get_code(self, fullname):
+        return compile('', '<string>', 'exec', dont_inherit=True)
+
+    def init_module_attrs(self, module):
+        module.__loader__ = self
+        module.__package__ = module.__name__
+
     def load_module(self, fullname):
         """Load a namespace module."""
         _verbose_message('namespace module loaded with path {!r}', self._path)
         with module_to_load(fullname) as module:
+            self.init_module_attrs(module)
             module.__path__ = self._path
-            module.__package__ = fullname
             return module