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.

Author vstinner
Recipients Trundle, flox, vstinner
Date 2010-09-03.22:08:25
SpamBayes Score 2.4401723e-07
Marked as misclassified No
Message-id <1283551706.49.0.0252323264007.issue9756@psf.upfronthosting.co.za>
In-reply-to
Content
>>> 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()).
History
Date User Action Args
2010-09-03 22:08:26vstinnersetrecipients: + vstinner, Trundle, flox
2010-09-03 22:08:26vstinnersetmessageid: <1283551706.49.0.0252323264007.issue9756@psf.upfronthosting.co.za>
2010-09-03 22:08:25vstinnerlinkissue9756 messages
2010-09-03 22:08:25vstinnercreate