Commits

holger krekel committed 6cb3976

default to __version__ '0' and not set __loader__ or __path__ at all if it
doesn't exist on the underlying init module

Comments (0)

Files changed (3)

 ----------------------------------------
 
 - fix recursive import issue resulting in a superflous KeyError 
+- default to __version__ '0' and not set __loader__ or __path__ at all if it
+  doesn't exist on the underlying init module
 
 1.0.0b5
 ----------------------------------------
     mod = ApiModule(pkgname, exportdefs, implprefix=pkgname)
     oldmod = sys.modules[pkgname]
     mod.__file__ = getattr(oldmod, '__file__', None)
-    mod.__version__ = getattr(oldmod, '__version__', None)
-    mod.__path__ = getattr(oldmod, '__path__', None)
-    mod.__loader__ = getattr(oldmod, '__loader__', None)
+    mod.__version__ = getattr(oldmod, '__version__', '0')
+    for name in ('__path__', '__loader__'):
+        if hasattr(oldmod, name):
+            setattr(mod, name, getattr(oldmod, name))
     sys.modules[pkgname]  = mod
 
 def importobj(modpath, attrname):
     assert newmod.__version__ == mod.__version__
     assert newmod.__loader__ == mod.__loader__
 
+def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
+    mod = type(sys)('hello')
+    mod.__file__ = "hello.py"
+    monkeypatch.setitem(sys.modules, 'hello', mod)
+    apipkg.initpkg('hello', {})
+    newmod = sys.modules['hello']
+    assert newmod != mod
+    assert newmod.__file__ == mod.__file__
+    assert not hasattr(newmod, '__loader__')
+    assert not hasattr(newmod, '__path__')
+
 def test_initpkg_defaults(monkeypatch):
     mod = type(sys)('hello')
     monkeypatch.setitem(sys.modules, 'hello', mod)
     apipkg.initpkg('hello', {})
     newmod = sys.modules['hello']
     assert newmod.__file__ == None
-    assert newmod.__version__ == None
+    assert newmod.__version__ == '0'
 
 def test_name_attribute():
     api = apipkg.ApiModule('name_test', {