mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
handle old-style instances
This commit is contained in:
parent
8de87a6403
commit
fd89af59e8
1 changed files with 10 additions and 3 deletions
|
@ -1906,14 +1906,21 @@ _dir_object(PyObject *obj)
|
||||||
{
|
{
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
static PyObject *dir_str = NULL;
|
static PyObject *dir_str = NULL;
|
||||||
PyObject *dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
|
PyObject *dirfunc;
|
||||||
|
|
||||||
assert(obj);
|
assert(obj);
|
||||||
if (dirfunc == NULL) {
|
if (PyInstance_Check(obj)) {
|
||||||
|
dirfunc = PyObject_GetAttrString(obj, "__dir__");
|
||||||
|
if (dirfunc == NULL && !PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
if (dirfunc == NULL) {
|
||||||
/* use default implementation */
|
/* use default implementation */
|
||||||
PyErr_Clear();
|
|
||||||
if (PyModule_Check(obj))
|
if (PyModule_Check(obj))
|
||||||
result = _specialized_dir_module(obj);
|
result = _specialized_dir_module(obj);
|
||||||
else if (PyType_Check(obj) || PyClass_Check(obj))
|
else if (PyType_Check(obj) || PyClass_Check(obj))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue