@@ -4536,7 +4536,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45364536 }
45374537 if (fromlist == NULL ) {
45384538 assert (!PyErr_Occurred ());
4539- fromlist = Py_NewRef ( Py_None ) ;
4539+ fromlist = Py_None ;
45404540 }
45414541 PyObject * args [] = {modname , abs_name , fromlist };
45424542 PyObject * res = PyObject_Vectorcall (filter , args , 3 , NULL );
@@ -4565,8 +4565,19 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45654565 }
45664566
45674567 // here, 'filter' is either NULL or is equivalent to a borrowed reference
4568+ if (fromlist && PyUnicode_Check (fromlist )) {
4569+ fromlist = PyTuple_Pack (1 , fromlist );
4570+ if (fromlist == NULL ) {
4571+ Py_DECREF (abs_name );
4572+ return NULL ;
4573+ }
4574+ }
4575+ else {
4576+ Py_XINCREF (fromlist );
4577+ }
45684578 PyObject * res = _PyLazyImport_New (frame , builtins , abs_name , fromlist );
45694579 if (res == NULL ) {
4580+ Py_XDECREF (fromlist );
45704581 Py_DECREF (abs_name );
45714582 return NULL ;
45724583 }
@@ -4577,13 +4588,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45774588 goto error ;
45784589 }
45794590
4580- if (fromlist && PyUnicode_Check (fromlist )) {
4581- if (register_from_lazy_on_parent (tstate , abs_name , fromlist ) < 0 ) {
4582- goto error ;
4583- }
4584- }
4585- else if (fromlist && PyTuple_Check (fromlist ) &&
4586- PyTuple_GET_SIZE (fromlist )) {
4591+ if (fromlist && PyTuple_Check (fromlist ) && PyTuple_GET_SIZE (fromlist )) {
45874592 for (Py_ssize_t i = 0 ; i < PyTuple_GET_SIZE (fromlist ); i ++ ) {
45884593 if (register_from_lazy_on_parent (tstate , abs_name ,
45894594 PyTuple_GET_ITEM (fromlist , i )) < 0 )
@@ -4596,9 +4601,11 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45964601 goto error ;
45974602 }
45984603
4604+ Py_XDECREF (fromlist );
45994605 Py_DECREF (abs_name );
46004606 return res ;
46014607error :
4608+ Py_XDECREF (fromlist );
46024609 Py_DECREF (abs_name );
46034610 Py_DECREF (res );
46044611 return NULL ;
0 commit comments