dir() doesn't reify module

This commit is contained in:
Dino Viehland 2025-10-07 14:52:23 -07:00
parent e5e9592863
commit aa85f9d79e
3 changed files with 27 additions and 1 deletions

View file

@ -1259,7 +1259,12 @@ static PyObject *
module_dir(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
PyObject *dict = PyObject_GetAttr(self, &_Py_ID(__dict__));
PyObject *dict;
if (PyModule_CheckExact(self)) {
dict = Py_NewRef(((PyModuleObject *)self)->md_dict);
} else {
dict = PyObject_GetAttr(self, &_Py_ID(__dict__));
}
if (dict != NULL) {
if (PyDict_Check(dict)) {