@@ -3706,6 +3706,7 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
37063706{
37073707 PyObject * obj = NULL ;
37083708 PyObject * fromlist = NULL ;
3709+ PyObject * import_func = NULL ;
37093710 assert (lazy_import != NULL );
37103711 assert (PyLazyImport_CheckExact (lazy_import ));
37113712
@@ -3723,7 +3724,7 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
37233724 }
37243725
37253726 int is_loading = PySet_Contains (importing , lazy_import );
3726- if (is_loading < 0 ) {
3727+ if (is_loading < 0 ) {
37273728 return NULL ;
37283729 } else if (is_loading == 1 ) {
37293730 PyObject * name = _PyLazyImport_GetName (lazy_import );
@@ -3766,9 +3767,8 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
37663767
37673768 PyObject * globals = PyEval_GetGlobals ();
37683769
3769- PyObject * import_func ;
37703770 if (PyMapping_GetOptionalItem (lz -> lz_builtins , & _Py_ID (__import__ ), & import_func ) < 0 ) {
3771- return NULL ;
3771+ goto error ;
37723772 }
37733773 if (full ) {
37743774 obj = _PyEval_ImportNameWithImport (tstate ,
@@ -3781,7 +3781,6 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
37813781 } else {
37823782 PyObject * name = PyUnicode_Substring (lz -> lz_from , 0 , dot );
37833783 if (name == NULL ) {
3784- Py_DECREF (import_func );
37853784 goto error ;
37863785 }
37873786 obj = _PyEval_ImportNameWithImport (tstate ,
@@ -3793,7 +3792,6 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
37933792 _PyLong_GetZero ());
37943793 Py_DECREF (name );
37953794 }
3796- Py_DECREF (import_func );
37973795 if (obj == NULL ) {
37983796 goto error ;
37993797 }
@@ -3891,6 +3889,7 @@ _PyImport_LoadLazyImportTstate(PyThreadState *tstate, PyObject *lazy_import)
38913889 }
38923890
38933891 Py_XDECREF (fromlist );
3892+ Py_XDECREF (import_func );
38943893 return obj ;
38953894}
38963895
@@ -4226,7 +4225,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
42264225 }
42274226
42284227 PyInterpreterState * interp = tstate -> interp ;
4229- assert (frame -> f_globals == frame -> f_locals ); // should only be called in global scope
4228+ assert (_PyEval_GetFrame () -> f_globals == _PyEval_GetFrame () -> f_locals ); // should only be called in global scope
42304229
42314230 // Check if the filter disables the lazy import
42324231 PyObject * filter = LAZY_IMPORTS_FILTER (interp );
@@ -5312,7 +5311,7 @@ _imp__set_lazy_attributes_impl(PyObject *module, PyObject *child_module,
53125311 goto error ;
53135312 }
53145313
5315- if (PyDict_SetItem (child_dict , attr_name , lazy_module_attr ) < 0 ) {
5314+ if (_PyModule_ReplaceLazyValue (child_dict , attr_name , lazy_module_attr ) < 0 ) {
53165315 Py_DECREF (lazy_module_attr );
53175316 goto error ;
53185317 }
0 commit comments