File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -718,8 +718,36 @@ module_getattro(PyModuleObject *m, PyObject *name)
718718 _Py_IDENTIFIER (__name__ );
719719 mod_name = _PyDict_GetItemId (m -> md_dict , & PyId___name__ );
720720 if (mod_name && PyUnicode_Check (mod_name )) {
721- PyErr_Format (PyExc_AttributeError ,
722- "module '%U' has no attribute '%U'" , mod_name , name );
721+ _Py_IDENTIFIER (__spec__ );
722+ _Py_IDENTIFIER (_initializing );
723+ PyObject * value = NULL ;
724+ PyObject * spec ;
725+ int initializing = 0 ;
726+ Py_INCREF (mod_name );
727+ spec = _PyDict_GetItemId (m -> md_dict , & PyId___spec__ );
728+ if (spec != NULL && spec != Py_None ) {
729+ value = _PyObject_GetAttrId (spec , & PyId__initializing );
730+ }
731+ if (value == NULL )
732+ PyErr_Clear ();
733+ else {
734+ initializing = PyObject_IsTrue (value );
735+ Py_DECREF (value );
736+ if (initializing < 0 )
737+ PyErr_Clear ();
738+ }
739+ if (initializing > 0 ) {
740+ PyErr_Format (PyExc_AttributeError ,
741+ "partially initialized "
742+ "module '%U' has no attribute '%U'" ,
743+ mod_name , name );
744+ }
745+ else {
746+ PyErr_Format (PyExc_AttributeError ,
747+ "module '%U' has no attribute '%U'" ,
748+ mod_name , name );
749+ }
750+ Py_DECREF (mod_name );
723751 return NULL ;
724752 }
725753 }
You can’t perform that action at this time.
0 commit comments