summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-03-19 04:39:13 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-03-19 04:39:13 (GMT)
commita4d77898db3856cd3d8c9411d024bea88be25b66 (patch)
treeda46cbbc8815fe69cadc7a44146970a56439b05c
parentde48d8406feb997fefdbad7fbdbf43f918805f2e (diff)
downloadcpython-a4d77898db3856cd3d8c9411d024bea88be25b66.zip
cpython-a4d77898db3856cd3d8c9411d024bea88be25b66.tar.gz
cpython-a4d77898db3856cd3d8c9411d024bea88be25b66.tar.bz2
Issue #2400: Allow relative imports to "import *".
-rw-r--r--Lib/test/relimport.py1
-rw-r--r--Lib/test/test_import.py14
-rw-r--r--Misc/NEWS2
-rw-r--r--Python/ast.c4
4 files changed, 16 insertions, 5 deletions
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 @@ 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()
diff --git a/Misc/NEWS b/Misc/NEWS
index 80bfd7b..a7fc021 100644
--- 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
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 @@ 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) */