[issue9756] Crash with custom __getattribute__
STINNER Victor
report at bugs.python.org
Sat Sep 4 00:08:26 CEST 2010
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
>>> class Spam(object):
... def __getattribute__(self, name):
... if name == '__class__':
... return str
... raise AttributeError
...
>>> spam = Spam('spam')
>>> isinstance(spam, str)
True
isinstance(spam, str) calls str.__instancecheck__(spam) (type___instancecheck__) which checks spam.__class__, and spam.__class__ is str.
--
>>> import re
>>> re.match('spam', spam)
TypeError: expected string or buffer
Here the result is different because _sre.compile(spam) calls getstring() which uses PyUnicode_Check(spam) (-> False) and does checks on the buffer API (-> False).
--
About str.title(spam): it calls methoddescr_call() which checks the type using... PyObject_IsInstance() (and not PyUnicode_Check()).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9756>
_______________________________________
More information about the Python-bugs-list
mailing list