Issue #2400: Allow relative imports to "import *".
diff --git a/Lib/test/relimport.py b/Lib/test/relimport.py
new file mode 100644
index 0000000..50aa497
--- /dev/null
+++ b/Lib/test/relimport.py
@@ -0,0 +1 @@
+from .test_import import *
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index a44170c..dfaad29 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -254,8 +254,20 @@
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()
diff --git a/Misc/NEWS b/Misc/NEWS
index 80bfd7b..a7fc021 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@
Core and builtins
-----------------
+- Issue #2400: Allow relative imports to "import *".
+
- Issue 1745. Backport print function with:
from __future__ import print_function
diff --git a/Python/ast.c b/Python/ast.c
index e14ff3a..8a317b8 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2413,10 +2413,6 @@
/* 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) */