Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
15 changes: 2 additions & 13 deletions 15 Lib/importlib/_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ def __init__(self, name, loader, *, origin=None, loader_state=None,
self.origin = origin
self.loader_state = loader_state
self.submodule_search_locations = [] if is_package else None
self._uninitialized_submodules = []

# file-location attributes
self._set_fileattr = False
Expand Down Expand Up @@ -988,7 +987,6 @@ def _sanity_check(name, package, level):
def _find_and_load_unlocked(name, import_):
path = None
parent = name.rpartition('.')[0]
parent_spec = None
if parent:
if parent not in sys.modules:
_call_with_frames_removed(import_, parent)
Expand All @@ -1001,24 +999,15 @@ def _find_and_load_unlocked(name, import_):
except AttributeError:
msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent)
raise ModuleNotFoundError(msg, name=name) from None
parent_spec = parent_module.__spec__
child = name.rpartition('.')[2]
spec = _find_spec(name, path)
if spec is None:
raise ModuleNotFoundError(_ERR_MSG.format(name), name=name)
else:
if parent_spec:
# Temporarily add child we are currently importing to parent's
# _uninitialized_submodules for circular import tracking.
parent_spec._uninitialized_submodules.append(child)
try:
module = _load_unlocked(spec)
finally:
if parent_spec:
parent_spec._uninitialized_submodules.pop()
module = _load_unlocked(spec)
if parent:
# Set the module as an attribute on its parent.
parent_module = sys.modules[parent]
child = name.rpartition('.')[2]
try:
setattr(parent_module, child, module)
except AttributeError:
Expand Down
10 changes: 0 additions & 10 deletions 10 Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,16 +1350,6 @@ def test_circular_from_import(self):
str(cm.exception),
)

def test_absolute_circular_submodule(self):
with self.assertRaises(AttributeError) as cm:
import test.test_import.data.circular_imports.subpkg2.parent
self.assertIn(
"cannot access submodule 'parent' of module "
"'test.test_import.data.circular_imports.subpkg2' "
"(most likely due to a circular import)",
str(cm.exception),
)

def test_unwritable_module(self):
self.addCleanup(unload, "test.test_import.data.unwritable")
self.addCleanup(unload, "test.test_import.data.unwritable.x")
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions 30 Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,30 +739,6 @@ _PyModuleSpec_IsInitializing(PyObject *spec)
return 0;
}

/* Check if the submodule name is in the "_uninitialized_submodules" attribute
of the module spec.
*/
int
_PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name)
{
if (spec == NULL) {
return 0;
}

_Py_IDENTIFIER(_uninitialized_submodules);
PyObject *value = _PyObject_GetAttrId(spec, &PyId__uninitialized_submodules);
if (value == NULL) {
return 0;
}

int is_uninitialized = PySequence_Contains(value, name);
Py_DECREF(value);
if (is_uninitialized == -1) {
return 0;
}
return is_uninitialized;
}

static PyObject*
module_getattro(PyModuleObject *m, PyObject *name)
{
Expand Down Expand Up @@ -797,12 +773,6 @@ module_getattro(PyModuleObject *m, PyObject *name)
"(most likely due to a circular import)",
mod_name, name);
}
else if (_PyModuleSpec_IsUninitializedSubmodule(spec, name)) {
PyErr_Format(PyExc_AttributeError,
"cannot access submodule '%U' of module '%U' "
"(most likely due to a circular import)",
name, mod_name);
}
else {
PyErr_Format(PyExc_AttributeError,
"module '%U' has no attribute '%U'",
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.