@@ -4592,39 +4592,54 @@ _imp__set_lazy_imports_in_module_impl(PyObject *module, PyObject *enabled)
4592
4592
}
4593
4593
4594
4594
static int
4595
- is_lazy_imports_active (PyInterpreterState * interp , _PyInterpreterFrame * frame )
4596
- {
4597
- int lazy_imports = interp -> lazy_imports ;
4598
- if (lazy_imports ) {
4599
- if (PyDict_CheckExact (frame -> f_globals )) {
4600
- PyObject * lazy_imports_enabled = PyDict_GetItem (frame -> f_globals , & _Py_ID (__lazy_imports_enabled__ ));
4601
- if (lazy_imports_enabled != NULL ) {
4602
- if (PyObject_IsTrue (lazy_imports_enabled ) != 1 ) {
4603
- lazy_imports = 0 ;
4604
- }
4605
- } else {
4606
- PyObject * modname = PyDict_GetItem (frame -> f_globals , & _Py_ID (__name__ ));
4607
- if (modname != NULL && modname != Py_None ) {
4608
- PyObject * filter = interp -> excluding_modules ;
4609
- if (filter != NULL && PySequence_Contains (filter , modname )) {
4610
- lazy_imports = 0 ; /* Module explicitly excluded from lazy importing */
4611
- }
4612
- PyDict_SetItem (frame -> f_globals , & _Py_ID (__lazy_imports_enabled__ ), lazy_imports ? Py_True : Py_False );
4613
- } else {
4614
- lazy_imports = 0 ;
4615
- }
4616
- }
4617
- } else {
4618
- lazy_imports = 0 ;
4595
+ is_lazy_imports_active (PyThreadState * tstate , _PyInterpreterFrame * frame )
4596
+ {
4597
+ int lazy_imports = tstate -> interp -> lazy_imports ;
4598
+ assert (lazy_imports != -1 );
4599
+ if (!lazy_imports ) {
4600
+ return 0 ;
4601
+ }
4602
+
4603
+ PyObject * filter = tstate -> interp -> excluding_modules ;
4604
+ if (filter == NULL ) {
4605
+ return 1 ;
4606
+ }
4607
+
4608
+ if (!PyDict_CheckExact (frame -> f_globals )) {
4609
+ return 0 ;
4610
+ }
4611
+
4612
+ PyObject * modname = PyDict_GetItem (frame -> f_globals , & _Py_ID (__name__ ));
4613
+ if (modname == NULL || Py_IsNone (modname )) {
4614
+ return 0 ;
4615
+ }
4616
+
4617
+ PyObject * lazy_imports_enabled = PyDict_GetItem (frame -> f_globals , & _Py_ID (__lazy_imports_enabled__ ));
4618
+ if (lazy_imports_enabled == NULL ) {
4619
+ int eager = PySequence_Contains (filter , modname );
4620
+ if (eager == -1 ) {
4621
+ _PyErr_Clear (tstate );
4622
+ return 0 ;
4623
+ }
4624
+ lazy_imports = eager ? 0 : 1 ;
4625
+ if (PyDict_SetItem (frame -> f_globals , & _Py_ID (__lazy_imports_enabled__ ), lazy_imports ? Py_True : Py_False ) == -1 ) {
4626
+ _PyErr_Clear (tstate );
4627
+ }
4628
+ } else {
4629
+ lazy_imports = PyObject_IsTrue (lazy_imports_enabled );
4630
+ if (lazy_imports == -1 ) {
4631
+ _PyErr_Clear (tstate );
4632
+ return 0 ;
4619
4633
}
4620
4634
}
4635
+
4621
4636
return lazy_imports ;
4622
4637
}
4623
4638
4624
4639
int
4625
4640
_PyImport_IsLazyImportsActive (PyThreadState * tstate )
4626
4641
{
4627
- return is_lazy_imports_active (tstate -> interp , tstate -> cframe -> current_frame );
4642
+ return is_lazy_imports_active (tstate , tstate -> cframe -> current_frame );
4628
4643
}
4629
4644
4630
4645
int
@@ -4640,7 +4655,7 @@ PyImport_IsLazyImportsEnabled(void)
4640
4655
assert (0 );
4641
4656
return 0 ;
4642
4657
}
4643
- return is_lazy_imports_active (tstate -> interp , frame );
4658
+ return is_lazy_imports_active (tstate , frame );
4644
4659
}
4645
4660
4646
4661
/*[clinic input]
0 commit comments