Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
code review
  • Loading branch information
hauntsaninja committed Dec 1, 2023
commit a1c7198e4dee1e07357a42ccdebf45deefc5c4ac
22 changes: 13 additions & 9 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,22 +841,26 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
}
if (suppress != 1) {
if (_PyModuleSpec_IsInitializing(spec)) {
origin = PyObject_GetAttr(spec, &_Py_ID(origin));
if (origin == NULL || origin == Py_None) {
PyErr_Format(PyExc_AttributeError,
"partially initialized "
"module '%U' has no attribute '%U' "
"(most likely due to a circular import)",
mod_name, name);
int valid_spec = PyObject_GetOptionalAttr(spec, &_Py_ID(origin), &origin);
// check if origin is a str object
if (valid_spec == 1 && !PyUnicode_Check(origin)) {
valid_spec = 0;
Py_DECREF(origin);
}
else {
if (valid_spec == 1) {
PyErr_Format(PyExc_AttributeError,
"partially initialized "
"module '%U' from '%U' has no attribute '%U' "
"(most likely due to a circular import)",
mod_name, origin, name);
Py_DECREF(origin);
} else {
PyErr_Format(PyExc_AttributeError,
"partially initialized "
"module '%U' has no attribute '%U' "
"(most likely due to a circular import)",
mod_name, name);
}
Py_XDECREF(origin);
}
else if (_PyModuleSpec_IsUninitializedSubmodule(spec, name)) {
PyErr_Format(PyExc_AttributeError,
Expand Down