mirror of https://github.com/python/cpython
Issue #2400: Allow relative imports to "import *".
This commit is contained in:
parent
de48d8406f
commit
a4d77898db
|
@ -0,0 +1 @@
|
||||||
|
from .test_import import *
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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) */
|
||||||
|
|
Loading…
Reference in New Issue