STINNER Victor <victor.stin...@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 <rep...@bugs.python.org> <http://bugs.python.org/issue9756> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com