Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r95012:dafacc40cdc4
Date: 2018-08-18 20:29 +0200
http://bitbucket.org/pypy/pypy/changeset/dafacc40cdc4/

Log:    Match CPython's buggy behavior when importing a name with a trailing
        dot

diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -394,6 +394,8 @@
 
     w_mod = None
     parts = modulename.split('.')
+    if parts[-1] == '':
+        del parts[-1]
     prefix = []
     w_path = None
 
diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -298,6 +298,13 @@
         assert ambig == sys.modules.get('ambig')
         assert hasattr(ambig,'imapackage')
 
+    def test_trailing_dot(self):
+        # bug-for-bug compatibility with CPython
+        import sys
+        __import__('pkg.pkg1.')
+        assert 'pkg.pkg1' in sys.modules
+        assert 'pkg.pkg1.' not in sys.modules
+
     def test_from_a(self):
         import sys
         from a import imamodule
@@ -751,7 +758,6 @@
             exec "from pkg.withoutall import *" in d
             assert "" in d
 
-
     def test_import_star_with_bogus___all__(self):
         for case in ["not-imported-yet", "already-imported"]:
             try:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to