X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,12 @@ def test_rebinding(self):
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.
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_import/data/circular_imports/binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import test.test_import.data.circular_imports.binding2 as binding2
1 change: 1 addition & 0 deletions Lib/test/test_import/data/circular_imports/binding2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import test.test_import.data.circular_imports.binding as binding
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
X Tutup