[pypy-svn] r4759 - in pypy/trunk/src/pypy/module: . test test/impsubdir test/impsubdir/ambig

alex at codespeak.net alex at codespeak.net
Mon May 31 16:30:19 CEST 2004


Author: alex
Date: Mon May 31 16:30:19 2004
New Revision: 4759

Added:
   pypy/trunk/src/pypy/module/test/impsubdir/ambig/
   pypy/trunk/src/pypy/module/test/impsubdir/ambig.py
   pypy/trunk/src/pypy/module/test/impsubdir/ambig/__init__.py
Modified:
   pypy/trunk/src/pypy/module/__builtin__interp.py
   pypy/trunk/src/pypy/module/test/test_import.py
Log:
On import, package must shadow module if both exist under the same
directory of sys.path



Modified: pypy/trunk/src/pypy/module/__builtin__interp.py
==============================================================================
--- pypy/trunk/src/pypy/module/__builtin__interp.py	(original)
+++ pypy/trunk/src/pypy/module/__builtin__interp.py	Mon May 31 16:30:19 2004
@@ -111,15 +111,14 @@
         return w_mod
     
     for path in space.unpackiterable(w_path):
+        dir = os.path.join(space.unwrap(path), partname)
+        if os.path.isdir(dir):
+            f = os.path.join(dir,'__init__.py')
+            w_mod = try_import_mod(w_modulename, f, pkgdir=dir)
+            if w_mod is not None:
+                return w_mod
         f = os.path.join(space.unwrap(path), partname + '.py')
-        w_mod = try_import_mod(w_modulename,f)
-        if w_mod is not None:
-            return w_mod
-        dir = os.path.join(space.unwrap(path),partname)
-        if not os.path.isdir(dir):
-            continue
-        f = os.path.join(dir,'__init__.py')
-        w_mod = try_import_mod(w_modulename,f,pkgdir=dir)
+        w_mod = try_import_mod(w_modulename, f)
         if w_mod is not None:
             return w_mod
 

Added: pypy/trunk/src/pypy/module/test/impsubdir/ambig.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/impsubdir/ambig.py	Mon May 31 16:30:19 2004
@@ -0,0 +1 @@
+imamodule = 1

Added: pypy/trunk/src/pypy/module/test/impsubdir/ambig/__init__.py
==============================================================================
--- (empty file)
+++ pypy/trunk/src/pypy/module/test/impsubdir/ambig/__init__.py	Mon May 31 16:30:19 2004
@@ -0,0 +1 @@
+imapackage = 1

Modified: pypy/trunk/src/pypy/module/test/test_import.py
==============================================================================
--- pypy/trunk/src/pypy/module/test/test_import.py	(original)
+++ pypy/trunk/src/pypy/module/test/test_import.py	Mon May 31 16:30:19 2004
@@ -40,7 +40,14 @@
       self.assert_('pkg' in sys.modules)
       self.assert_('pkg.pkg1' in sys.modules)
       self.assert_('pkg.pkg1.a' in sys.modules)
-      
+
+   def test_import_ambig(self):
+      import sys
+      sys.path.append('impsubdir')
+      import ambig
+      self.assert_('ambig' in sys.modules)
+      self.assert_(hasattr(ambig,'imapackage'))
+       
 if __name__ == '__main__':
     testit.main()
 



More information about the Pypy-commit mailing list