@@ -4539,7 +4539,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45394539 }
45404540 if (fromlist == NULL ) {
45414541 assert (!PyErr_Occurred ());
4542- fromlist = Py_NewRef ( Py_None ) ;
4542+ fromlist = Py_None ;
45434543 }
45444544 PyObject * args [] = {modname , abs_name , fromlist };
45454545 PyObject * res = PyObject_Vectorcall (filter , args , 3 , NULL );
@@ -4568,8 +4568,19 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45684568 }
45694569
45704570 // here, 'filter' is either NULL or is equivalent to a borrowed reference
4571+ if (fromlist && PyUnicode_Check (fromlist )) {
4572+ fromlist = PyTuple_Pack (1 , fromlist );
4573+ if (fromlist == NULL ) {
4574+ Py_DECREF (abs_name );
4575+ return NULL ;
4576+ }
4577+ }
4578+ else {
4579+ Py_XINCREF (fromlist );
4580+ }
45714581 PyObject * res = _PyLazyImport_New (frame , builtins , abs_name , fromlist );
45724582 if (res == NULL ) {
4583+ Py_XDECREF (fromlist );
45734584 Py_DECREF (abs_name );
45744585 return NULL ;
45754586 }
@@ -4580,13 +4591,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45804591 goto error ;
45814592 }
45824593
4583- if (fromlist && PyUnicode_Check (fromlist )) {
4584- if (register_from_lazy_on_parent (tstate , abs_name , fromlist ) < 0 ) {
4585- goto error ;
4586- }
4587- }
4588- else if (fromlist && PyTuple_Check (fromlist ) &&
4589- PyTuple_GET_SIZE (fromlist )) {
4594+ if (fromlist && PyTuple_Check (fromlist ) && PyTuple_GET_SIZE (fromlist )) {
45904595 for (Py_ssize_t i = 0 ; i < PyTuple_GET_SIZE (fromlist ); i ++ ) {
45914596 if (register_from_lazy_on_parent (tstate , abs_name ,
45924597 PyTuple_GET_ITEM (fromlist , i )) < 0 )
@@ -4599,9 +4604,11 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
45994604 goto error ;
46004605 }
46014606
4607+ Py_XDECREF (fromlist );
46024608 Py_DECREF (abs_name );
46034609 return res ;
46044610error :
4611+ Py_XDECREF (fromlist );
46054612 Py_DECREF (abs_name );
46064613 Py_DECREF (res );
46074614 return NULL ;
0 commit comments