File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -1654,9 +1654,7 @@ static PyObject *
1654
1654
whichmodule (PyObject * global , PyObject * dotted_path )
1655
1655
{
1656
1656
PyObject * module_name ;
1657
- PyObject * modules_dict ;
1658
- PyObject * module ;
1659
- Py_ssize_t i ;
1657
+ PyObject * modules ;
1660
1658
_Py_IDENTIFIER (__module__ );
1661
1659
_Py_IDENTIFIER (modules );
1662
1660
_Py_IDENTIFIER (__main__ );
@@ -1679,15 +1677,16 @@ whichmodule(PyObject *global, PyObject *dotted_path)
1679
1677
assert (module_name == NULL );
1680
1678
1681
1679
/* Fallback on walking sys.modules */
1682
- modules_dict = _PySys_GetObjectId (& PyId_modules );
1683
- if (modules_dict == NULL ) {
1680
+ modules = _PySys_GetObjectId (& PyId_modules );
1681
+ if (modules == NULL ) {
1684
1682
PyErr_SetString (PyExc_RuntimeError , "unable to get sys.modules" );
1685
1683
return NULL ;
1686
1684
}
1687
1685
1688
- i = 0 ;
1689
- while (PyDict_Next ( modules_dict , & i , & module_name , & module )) {
1686
+ PyObject * iterator = PyObject_GetIter ( modules ) ;
1687
+ while (( module_name = PyIter_Next ( iterator ) )) {
1690
1688
PyObject * candidate ;
1689
+ PyObject * module = PyObject_GetItem (modules , module_name );
1691
1690
if (PyUnicode_Check (module_name ) &&
1692
1691
_PyUnicode_EqualToASCIIString (module_name , "__main__" ))
1693
1692
continue ;
You can’t perform that action at this time.
0 commit comments