Message115515
>>> 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()). |
|
Date |
User |
Action |
Args |
2010-09-03 22:08:26 | vstinner | set | recipients:
+ vstinner, Trundle, flox |
2010-09-03 22:08:26 | vstinner | set | messageid: <1283551706.49.0.0252323264007.issue9756@psf.upfronthosting.co.za> |
2010-09-03 22:08:25 | vstinner | link | issue9756 messages |
2010-09-03 22:08:25 | vstinner | create | |
|