[py-svn] apipkg commit 8c7bb85c04f1: fix recursive import error

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jan 21 20:01:26 CET 2010


# HG changeset patch -- Bitbucket.org
# Project apipkg
# URL http://bitbucket.org/hpk42/apipkg/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1264099537 -3600
# Node ID 8c7bb85c04f17cf3de710d7323ebe852d64ac8e5
# Parent 47e2df93097a5dc5cfcf978a754342ba47bab8c3
fix recursive import error

--- a/test_apipkg.py
+++ b/test_apipkg.py
@@ -105,6 +105,24 @@ class TestScenarios:
         assert mymodule.__doc__ == 'hello'
         assert mymodule.y.z == 3
 
+    def test_recursive_import(self, monkeypatch, tmpdir):
+        pkgdir = tmpdir.mkdir("recmodule")
+        pkgdir.join('__init__.py').write(py.code.Source("""
+            import apipkg
+            apipkg.initpkg(__name__, exportdefs={
+                'some': '.submod:someclass',
+            })
+        """))
+        pkgdir.join('submod.py').write(py.code.Source("""
+            import recmodule 
+            class someclass: pass
+            print (recmodule.__dict__)
+        """))
+        monkeypatch.syspath_prepend(tmpdir)
+        import recmodule 
+        assert isinstance(recmodule, apipkg.ApiModule)
+        assert recmodule.some.__name__ == "someclass"
+
 def xtest_nested_absolute_imports():
     import email
     api_email = apipkg.ApiModule('email',{

--- a/apipkg.py
+++ b/apipkg.py
@@ -8,7 +8,7 @@ see http://pypi.python.org/pypi/apipkg
 import sys
 from types import ModuleType
 
-__version__ = "1.0b5"
+__version__ = "1.0b6"
 
 def initpkg(pkgname, exportdefs):
     """ initialize given package from the export definitions. """
@@ -71,7 +71,10 @@ class ApiModule(ModuleType):
         else:
             result = importobj(modpath, attrname)
             setattr(self, name, result)
-            del self.__map__[name]
+            try:
+                del self.__map__[name]
+            except KeyError:
+                pass # in a recursive-import situation a double-del can happen
             return result
 
     __getattr__ = __makeattr

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,18 @@
+1.0.0b6
+----------------------------------------
+
+- fix recursive import issue resulting in a superflous KeyError 
+
+1.0.0b5
+----------------------------------------
+
+- fixed MANIFEST.in
+- also transfer __loader__ attribute (thanks Ralf Schmitt) 
+- compat fix for BPython 
+
 1.0.0b3 (compared to 1.0.0b2)
 ------------------------------------
 
 - added special __onfirstaccess__ attribute whose value will 
   be called on the first attribute access of an apimodule. 
+



More information about the pytest-commit mailing list