[issue3471] PyObject_GetAttr() to get special methods
Armin Rigo
report at bugs.python.org
Wed Jul 30 18:38:35 CEST 2008
New submission from Armin Rigo <arigo at users.sourceforge.net>:
There is a bunch of obscure behavior caused by the use of
PyObject_GetAttr() to get special method from objects. This is wrong
because special methods should only be looked up in object types, not on
the objects themselves (i.e. with PyType_Lookup()).
Here is one example caused by the PyObject_GetAttr() found in
PyObject_IsInstance():
import abc
>>> isinstance(5, abc.ABCMeta)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded while calling a
Python object
This occurs because it ends up trying to call the unbound method
abc.ABCMeta.__instancecheck__(5). But this first requires checking if
"5" is indeed an instance of abc.ABCMeta... cycle.
Obviously this is just an example; all PyObject_GetAttr() would
potentially need to be reviewed.
----------
messages: 70431
nosy: arigo
severity: normal
status: open
title: PyObject_GetAttr() to get special methods
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3471>
_______________________________________
More information about the Python-bugs-list
mailing list