diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-09 19:31:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-09 19:31:05 (GMT) |
commit | f93234bb8a87855f295d441524e519481ce6ab13 (patch) | |
tree | df779655af5c9119aee4440fdb428b210bb09f92 | |
parent | dbdea629e2e0e4bd8845aa55041e0a0ca4172cf3 (diff) | |
download | cpython-f93234bb8a87855f295d441524e519481ce6ab13.zip cpython-f93234bb8a87855f295d441524e519481ce6ab13.tar.gz cpython-f93234bb8a87855f295d441524e519481ce6ab13.tar.bz2 |
bpo-30024: Circular imports involving absolute imports with binding (#1264)
a submodule to a name are now supported.
-rw-r--r-- | Doc/whatsnew/3.7.rst | 4 | ||||
-rw-r--r-- | Lib/test/test_import/__init__.py | 6 | ||||
-rw-r--r-- | Lib/test/test_import/data/circular_imports/binding.py | 1 | ||||
-rw-r--r-- | Lib/test/test_import/data/circular_imports/binding2.py | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/compile.c | 4 |
6 files changed, 17 insertions, 2 deletions
diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index b2dc995..3de8bc5 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -85,6 +85,10 @@ Other Language Changes * :exc:`ImportError` now displays module name and module ``__file__`` path when ``from ... import ...`` fails. (Contributed by Matthias Bussonnier in :issue:`29546`.) +* Circular imports involving absolute imports with binding a submodule to + a name are now supported. + (Contributed by Serhiy Storchaka in :issue:`30024`.) + New Modules =========== diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index d4b4445..be17d6b 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -1168,6 +1168,12 @@ class CircularImportTests(unittest.TestCase): from test.test_import.data.circular_imports.subpkg import util self.assertIs(util.util, rebinding.util) + def test_binding(self): + try: + import test.test_import.data.circular_imports.binding + except ImportError: + self.fail('circular import with binding a submodule to a name failed') + if __name__ == '__main__': # Test needs to be a package, so we can do relative imports. diff --git a/Lib/test/test_import/data/circular_imports/binding.py b/Lib/test/test_import/data/circular_imports/binding.py new file mode 100644 index 0000000..1fbf929 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/binding.py @@ -0,0 +1 @@ +import test.test_import.data.circular_imports.binding2 as binding2 diff --git a/Lib/test/test_import/data/circular_imports/binding2.py b/Lib/test/test_import/data/circular_imports/binding2.py new file mode 100644 index 0000000..3d66937 --- /dev/null +++ b/Lib/test/test_import/data/circular_imports/binding2.py @@ -0,0 +1 @@ +import test.test_import.data.circular_imports.binding as binding @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1? Core and Builtins ----------------- +- bpo-30024: Circular imports involving absolute imports with binding + a submodule to a name are now supported. + - bpo-12414: sys.getsizeof() on a code object now returns the sizes which includes the code struct and sizes of objects which it references. Patch by Dong-hee Na. diff --git a/Python/compile.c b/Python/compile.c index b630863..dad7404 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2546,7 +2546,7 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname) merely needs to bind the result to a name. If there is a dot in name, we need to split it and emit a - LOAD_ATTR for each name. + IMPORT_FROM for each name. */ Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0, PyUnicode_GET_LENGTH(name), 1); @@ -2566,7 +2566,7 @@ compiler_import_as(struct compiler *c, identifier name, identifier asname) PyUnicode_GET_LENGTH(name)); if (!attr) return 0; - ADDOP_O(c, LOAD_ATTR, attr, names); + ADDOP_O(c, IMPORT_FROM, attr, names); Py_DECREF(attr); pos = dot + 1; } |