From: Martin v. Löwis Date: Wed, 19 Mar 2008 04:39:13 +0000 (+0000) Subject: Issue #2400: Allow relative imports to "import *". X-Git-Tag: v2.6a2~238 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4d77898db3856cd3d8c9411d024bea88be25b66;p=python Issue #2400: Allow relative imports to "import *". --- diff --git a/Lib/test/relimport.py b/Lib/test/relimport.py new file mode 100644 index 0000000000..50aa497f7b --- /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 a44170c9d7..dfaad2916e 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 80bfd7b3cd..a7fc021bba 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 e14ff3a3da..8a317b880d 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) */