Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f5fcd33

Browse files
committed
merge 3.1
2 parents 4b244ef + 7963a35 commit f5fcd33

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

Lib/test/test_descr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,7 @@ def format_impl(self, spec):
15871587
("__floor__", math.floor, zero, set(), {}),
15881588
("__trunc__", math.trunc, zero, set(), {}),
15891589
("__ceil__", math.ceil, zero, set(), {}),
1590+
("__dir__", dir, empty_seq, set(), {}),
15901591
]
15911592

15921593
class Checker(object):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Correct lookup of __dir__ on objects. Among other things, this causes errors
17+
besides AttributeError found on lookup to be propagated.
18+
1619
- Issue #12124: zipimport doesn't keep a reference to zlib.decompress() anymore
1720
to be able to unload the module.
1821

Objects/object.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,14 +1366,15 @@ _generic_dir(PyObject *obj)
13661366
static PyObject *
13671367
_dir_object(PyObject *obj)
13681368
{
1369-
PyObject * result = NULL;
1370-
PyObject * dirfunc = PyObject_GetAttrString((PyObject*)obj->ob_type,
1371-
"__dir__");
1369+
PyObject *result = NULL;
1370+
static PyObject *dir_str = NULL;
1371+
PyObject *dirfunc = _PyObject_LookupSpecial(obj, "__dir__", &dir_str);
13721372

13731373
assert(obj);
13741374
if (dirfunc == NULL) {
1375+
if (PyErr_Occurred())
1376+
return NULL;
13751377
/* use default implementation */
1376-
PyErr_Clear();
13771378
if (PyModule_Check(obj))
13781379
result = _specialized_dir_module(obj);
13791380
else if (PyType_Check(obj))
@@ -1383,7 +1384,7 @@ _dir_object(PyObject *obj)
13831384
}
13841385
else {
13851386
/* use __dir__ */
1386-
result = PyObject_CallFunctionObjArgs(dirfunc, obj, NULL);
1387+
result = PyObject_CallFunctionObjArgs(dirfunc, NULL);
13871388
Py_DECREF(dirfunc);
13881389
if (result == NULL)
13891390
return NULL;

0 commit comments

Comments
 (0)