[Python-Dev] Semantic of isinstance

"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