[pypy-svn] r77529 - in pypy/trunk/pypy/module/imp: . test

afa at codespeak.net afa at codespeak.net
Fri Oct 1 16:43:33 CEST 2010


Author: afa
Date: Fri Oct  1 16:43:31 2010
New Revision: 77529

Modified:
   pypy/trunk/pypy/module/imp/importing.py
   pypy/trunk/pypy/module/imp/test/test_import.py
Log:
Avoid a crash when "from .. import x" is used at toplevel.


Modified: pypy/trunk/pypy/module/imp/importing.py
==============================================================================
--- pypy/trunk/pypy/module/imp/importing.py	(original)
+++ pypy/trunk/pypy/module/imp/importing.py	Fri Oct  1 16:43:31 2010
@@ -122,7 +122,7 @@
                     n = len(ctxt_name_prefix_parts)-level+1
                     assert n>=0
                     ctxt_name_prefix_parts = ctxt_name_prefix_parts[:n]
-                if ctxt_w_path is None: # plain module
+                if ctxt_name_prefix_parts and ctxt_w_path is None: # plain module
                     ctxt_name_prefix_parts.pop()
                 if ctxt_name_prefix_parts:
                     rel_modulename = '.'.join(ctxt_name_prefix_parts)

Modified: pypy/trunk/pypy/module/imp/test/test_import.py
==============================================================================
--- pypy/trunk/pypy/module/imp/test/test_import.py	(original)
+++ pypy/trunk/pypy/module/imp/test/test_import.py	Fri Oct  1 16:43:31 2010
@@ -360,6 +360,12 @@
         """.rstrip()
         raises(ValueError, imp)
 
+    def test_future_relative_import_error_when_in_non_package2(self):
+        exec """def imp():
+                    from .. import inpackage
+        """.rstrip()
+        raises(ValueError, imp)
+
     def test_relative_import_with___name__(self):
         import sys
         mydict = {'__name__': 'sys.foo'}



More information about the Pypy-commit mailing list