Issue #2400: Allow relative imports to "import *".

This commit is contained in:
Martin v. Löwis 2008-03-19 04:39:13 +00:00
parent de48d8406f
commit a4d77898db
4 changed files with 16 additions and 5 deletions

1
Lib/test/relimport.py Normal file
View File

@ -0,0 +1 @@
from .test_import import *

View File

@ -254,8 +254,20 @@ class PathsTests(unittest.TestCase):
self.assertEqual(mod.testdata, 'test_trailing_slash') self.assertEqual(mod.testdata, 'test_trailing_slash')
unload("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): def test_main(verbose=None):
run_unittest(ImportTest, PathsTests) run_unittest(ImportTest, PathsTests, RelativeImport)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()

View File

@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 2?
Core and builtins Core and builtins
----------------- -----------------
- Issue #2400: Allow relative imports to "import *".
- Issue 1745. Backport print function with: - Issue 1745. Backport print function with:
from __future__ import print_function from __future__ import print_function

View File

@ -2413,10 +2413,6 @@ ast_for_import_stmt(struct compiling *c, const node *n)
/* from ... import * */ /* from ... import * */
n = CHILD(n, idx); n = CHILD(n, idx);
n_children = 1; n_children = 1;
if (ndots) {
ast_error(n, "'import *' not allowed with 'from .'");
return NULL;
}
break; break;
case LPAR: case LPAR:
/* from ... import (x, y, z) */ /* from ... import (x, y, z) */