[Python-Dev] Semantic of isinstance (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Tue Jun 27 14:49:59 CEST 2006


Phillip J. Eby wrote:

It seems that the class is only accessed in some cases, but not always, leading to what I think is a semantic inconsistency. It's not inconsistent - isinstance() checks class in addition to type() in order to allow proxying tricks like lying about your class. It therefore returns true if either your real type or your class matches, and as you can see, the real type is checked first.

This is not the original rationale, though: the check for a class attribute on non-instance objects was introduced in r13520, to support ExtensionClasses. I never fully understood ExtensionClasses, but I believe they were not based on proxying tricks. Instead, they were an early version of new-style classes.

Regards, Martin



More information about the Python-Dev mailing list