[py-svn] py-trunk commit c93eada6c865: upgrade apipkg.py to fix a potential recursive import issue

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jan 21 20:07:25 CET 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1264100810 -3600
# Node ID c93eada6c8658c505d50803aa3541aa6f278897b
# Parent d14f120487dd94101a8c3d659c1b70306c1c7a88
upgrade apipkg.py to fix a potential recursive import issue

--- a/py/apipkg.py
+++ b/py/apipkg.py
@@ -8,16 +8,17 @@ see http://pypi.python.org/pypi/apipkg
 import sys
 from types import ModuleType
 
-__version__ = "1.0b4"
+__version__ = "1.0b6"
 
 def initpkg(pkgname, exportdefs):
     """ initialize given package from the export definitions. """
     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):
@@ -71,7 +72,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
@@ -2,6 +2,8 @@ Changes between 1.2.1 and 1.2.0
 =====================================
 
 - fix issue63: assume <40 columns to be a bogus terminal width, default to 80
+- update apipkg.py to fix an issue where recursive imports might
+  unnecessarily break importing 
 - fix plugin links 
 
 Changes between 1.2 and 1.1.1



More information about the pytest-commit mailing list