From a4d77898db3856cd3d8c9411d024bea88be25b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 19 Mar 2008 04:39:13 +0000 Subject: Issue #2400: Allow relative imports to "import *". --- Lib/test/relimport.py | 1 + Lib/test/test_import.py | 14 +++++++++++++- Misc/NEWS | 2 ++ Python/ast.c | 4 ---- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 Lib/test/relimport.py 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) */ -- cgit v0.12