[pypy-commit] pypy py3.5: Fix nested namespace packages in zipimport.

mjacob pypy.commits at gmail.com
Thu Mar 16 20:50:18 EDT 2017


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3.5
Changeset: r90735:9068bed7f373
Date: 2017-03-17 01:49 +0100
http://bitbucket.org/pypy/pypy/changeset/9068bed7f373/

Log:	Fix nested namespace packages in zipimport.

diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -373,7 +373,7 @@
             if self.have_modulefile(space, filename + ext):
                 return True, None
         # See if this is a directory (part of a namespace pkg)
-        dirpath = self.prefix + fullname
+        dirpath = self.prefix + fullname.split(".")[-1]
         if self.have_modulefile(space, dirpath + ZIPSEP):
             return True, self.filename + os.path.sep + self.corr_zname(dirpath)
         return False, None
diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py
--- a/pypy/module/zipimport/test/test_zipimport.py
+++ b/pypy/module/zipimport/test/test_zipimport.py
@@ -446,6 +446,13 @@
         foo = __import__('foo.one', None, None, [])
         assert foo.one.attr == 'portion1 foo one'
 
+    def test_namespace_pkg_nested(self):
+        self.writefile('foo/', '')
+        self.writefile('foo/bar/', '')
+        self.writefile('foo/bar/one.py', "attr = 'portion1 foo one'\n")
+        foo = __import__('foo.bar.one', None, None, [])
+        assert foo.bar.one.attr == 'portion1 foo one'
+
 
 if os.sep != '/':
     class AppTestNativePathSep(AppTestZipimport):


More information about the pypy-commit mailing list