]> granicus.if.org Git - python/commitdiff
Issue #2400: Allow relative imports to "import *".
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 19 Mar 2008 04:39:13 +0000 (04:39 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 19 Mar 2008 04:39:13 +0000 (04:39 +0000)
Lib/test/relimport.py [new file with mode: 0644]
Lib/test/test_import.py
Misc/NEWS
Python/ast.c

diff --git a/Lib/test/relimport.py b/Lib/test/relimport.py
new file mode 100644 (file)
index 0000000..50aa497
--- /dev/null
@@ -0,0 +1 @@
+from .test_import import *
index a44170c9d75a62203fe150efc14abfb12129ad43..dfaad2916e686faaf584a770735d002591a7f4d4 100644 (file)
@@ -254,8 +254,20 @@ class PathsTests(unittest.TestCase):
         self.assertEqual(mod.testdata, 'test_trailing_slash')
         unload("test_trailing_slash")
 
+class RelativeImport(unittest.TestCase):
+    def tearDown(self):
+        try:
+            del sys.modules["test.relimport"]
+        except:
+            pass
+
+    def test_relimport_star(self):
+        # This will import * from .test_import.
+        import relimport
+        self.assertTrue(hasattr(relimport, "RelativeImport"))
+
 def test_main(verbose=None):
-    run_unittest(ImportTest, PathsTests)
+    run_unittest(ImportTest, PathsTests, RelativeImport)
 
 if __name__ == '__main__':
     test_main()
index 80bfd7b3cdc2b0ea9e513694ffaac88020c6d5ed..a7fc021bbaeca4d73ec44e63f453095806ffb16d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
 Core and builtins
 -----------------
 
+- Issue #2400: Allow relative imports to "import *".
+
 - Issue 1745.  Backport print function with:
    from __future__ import print_function
 
index e14ff3a3da19a055fd57ccc467fdea36fdfa18bb..8a317b880dcc30f594938ea7f4294f04a74a3087 100644 (file)
@@ -2413,10 +2413,6 @@ ast_for_import_stmt(struct compiling *c, const node *n)
             /* from ... import * */
             n = CHILD(n, idx);
             n_children = 1;
-            if (ndots) {
-                ast_error(n, "'import *' not allowed with 'from .'");
-                return NULL;
-            }
             break;
         case LPAR:
             /* from ... import (x, y, z) */