Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Dec 1, 2023
1 parent 7222653 commit a1c7198
Showing 1 changed file with 13 additions and 9 deletions.
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

0 comments on commit a1c7198

Please sign in to comment.