This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: PyObject_GetAttr() to get special methods
Type: behavior Stage: test needed
Components: Interpreter Core Versions: Python 3.1, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: ajaksu2, arigo, benjamin.peterson
Priority: normal Keywords:

Created on 2008-07-30 16:38 by arigo, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg70431 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2008-07-30 16:38
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

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.
msg87928 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-05-16 20:43
This snippet is fixed (returns False), see issue 2325:

import abc
isinstance(5, abc.ABCMeta)

The general PyObject_GetAttr issue should be reviewed.
msg87938 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-05-16 21:57
I fixed the PyObject_GetAttr issue in r72690. I've also been working on
fixing the lookup of other special methods. Armin, do you have a list of
methods we should check?
msg95801 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-11-29 01:01
I'm closing this now.
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47721
2009-11-29 01:01:23benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg95801
2009-05-16 21:57:51benjamin.petersonsetassignee: benjamin.peterson
messages: + msg87938
2009-05-16 20:43:03ajaksu2setpriority: normal

type: behavior
components: + Interpreter Core
versions: + Python 2.6, Python 3.1
nosy: + ajaksu2, benjamin.peterson

messages: + msg87928
stage: test needed
2008-07-30 16:38:34arigocreate