mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
PyObject_Dir():
- use PyModule_Check() instead of PyObject_TypeCheck(), now we can. - don't assert that the __dict__ gotten out of a module is always a dictionary; check its type, and raise an exception if it's not.
This commit is contained in:
parent
b875509310
commit
8dbd3d8c50
1 changed files with 6 additions and 2 deletions
|
@ -1424,11 +1424,15 @@ PyObject_Dir(PyObject *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Elif this is some form of module, we only want its dict. */
|
/* Elif this is some form of module, we only want its dict. */
|
||||||
else if (PyObject_TypeCheck(arg, &PyModule_Type)) {
|
else if (PyModule_Check(arg)) {
|
||||||
masterdict = PyObject_GetAttrString(arg, "__dict__");
|
masterdict = PyObject_GetAttrString(arg, "__dict__");
|
||||||
if (masterdict == NULL)
|
if (masterdict == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
assert(PyDict_Check(masterdict));
|
if (!PyDict_Check(masterdict)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"module.__dict__ is not a dictionary");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Elif some form of type or class, grab its dict and its bases.
|
/* Elif some form of type or class, grab its dict and its bases.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue