Skip to content

Commit e56238b

Browse files
DinoVfacebook-github-bot
authored andcommitted
Port D70667959 and D70795133 to 3.12
Summary: This just ports this missing change over to 3.12. The test failures are related to D79649298. Reviewed By: itamaro Differential Revision: D79590225 fbshipit-source-id: 4ad15d3cfd5e356177a4213960748da91e58a0b9
1 parent 225ebe8 commit e56238b

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Python/import.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,18 @@ add_lazy_modules(PyThreadState *tstate, PyObject *builtins, PyObject *name, PyOb
30343034
if (res < 0) {
30353035
goto error;
30363036
} else if (!res) {
3037+
PyObject *existing = import_get_module(tstate, name);
3038+
Py_XDECREF(existing);
3039+
if (existing != NULL && _PyDict_GetItemKeepLazy(parent_dict, child) != NULL) {
3040+
// If the module is already loaded we don't need to do the below, we should
3041+
// have already recorded the module as a lazy module. Even if we've loaded
3042+
// the module previously we may return 1 (meaning load lazily), but that's
3043+
// because we want to continue processing the names in the fromlist lazily.
3044+
// If we return 0 (meaning load eagerly) we'll end up loading the fromlist
3045+
// eagerly too.
3046+
goto end;
3047+
}
3048+
30373049
PyObject *lazy_module_attr = _PyLazyImport_New(builtins, parent, child);
30383050
if (lazy_module_attr == NULL) {
30393051
goto error;

0 commit comments

Comments
 (0)