Commits

Ralf Schmitt  committed fd590ef

make initpkg work without an "old module" in sys.modules

  • Participants
  • Parent commits 41f548c

Comments (0)

Files changed (2)

 
 def initpkg(pkgname, exportdefs, attr=dict()):
     """ initialize given package from the export definitions. """
-    oldmod = sys.modules[pkgname]
+    oldmod = sys.modules.get(pkgname)
     d = {}
     f = getattr(oldmod, '__file__', None)
     if f:
     if hasattr(oldmod, '__doc__'):
         d['__doc__'] = oldmod.__doc__
     d.update(attr)
-    oldmod.__dict__.update(d)
+    if hasattr(oldmod, "__dict__"):
+        oldmod.__dict__.update(d)
     mod = ApiModule(pkgname, exportdefs, implprefix=pkgname, attr=d)
     sys.modules[pkgname]  = mod
 

File test_apipkg.py

     assert "<AliasModule 'mymod' for 'sys'>" == r
     am.version
     assert repr(am) == r
+
+def test_initpkg_without_old_module():
+    apipkg.initpkg("initpkg_without_old_module",
+                   dict(modules="sys:modules"))
+    from initpkg_without_old_module import modules
+    assert modules is sys.modules