Skip to content

Commit 47c948f

Browse files
author
martin.v.loewis
committed
Issue #2400: Allow relative imports to "import *".
git-svn-id: http://svn.python.org/projects/python/trunk@61595 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c27d2ee commit 47c948f

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

Lib/test/relimport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .test_import import *

Lib/test/test_import.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,20 @@ def test_trailing_slash(self):
254254
self.assertEqual(mod.testdata, 'test_trailing_slash')
255255
unload("test_trailing_slash")
256256

257+
class RelativeImport(unittest.TestCase):
258+
def tearDown(self):
259+
try:
260+
del sys.modules["test.relimport"]
261+
except:
262+
pass
263+
264+
def test_relimport_star(self):
265+
# This will import * from .test_import.
266+
import relimport
267+
self.assertTrue(hasattr(relimport, "RelativeImport"))
268+
257269
def test_main(verbose=None):
258-
run_unittest(ImportTest, PathsTests)
270+
run_unittest(ImportTest, PathsTests, RelativeImport)
259271

260272
if __name__ == '__main__':
261273
test_main()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
1212
Core and builtins
1313
-----------------
1414

15+
- Issue #2400: Allow relative imports to "import *".
16+
1517
- Issue 1745. Backport print function with:
1618
from __future__ import print_function
1719

Python/ast.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,10 +2413,6 @@ ast_for_import_stmt(struct compiling *c, const node *n)
24132413
/* from ... import * */
24142414
n = CHILD(n, idx);
24152415
n_children = 1;
2416-
if (ndots) {
2417-
ast_error(n, "'import *' not allowed with 'from .'");
2418-
return NULL;
2419-
}
24202416
break;
24212417
case LPAR:
24222418
/* from ... import (x, y, z) */

0 commit comments

Comments
 (0)