mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Add PyExc_ImportCycleError and raise it when a cycle is detected
This commit is contained in:
parent
00e7800e4c
commit
781eedb9d4
9 changed files with 57 additions and 15 deletions
|
|
@ -1046,6 +1046,13 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
|
|||
if (PyLazyImport_CheckExact(attr)) {
|
||||
PyObject *new_value = _PyImport_LoadLazyImportTstate(PyThreadState_GET(), attr);
|
||||
if (new_value == NULL) {
|
||||
if (suppress && PyErr_ExceptionMatches(PyExc_ImportCycleError)) {
|
||||
// ImportCycleError is raised when a lazy object tries to import itself.
|
||||
// In this case, the error should not propagate to the caller and
|
||||
// instead treated as if the attribute doesn't exist.
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
} else if (PyDict_SetItem(m->md_dict, name, new_value) < 0) {
|
||||
Py_DECREF(new_value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue