something wrong with isinstance
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Feb 13 05:59:01 EST 2009
En Fri, 13 Feb 2009 08:43:03 -0200, Peter Otten <__peter__ at web.de>
escribió:
> Gabriel Genellina wrote:
>> En Fri, 13 Feb 2009 08:07:58 -0200, Carl Banks
>> <pavlovevidence at gmail.com>
>> escribió:
>>> But that brings up another very slight possibility, though not a very
>>> likely one in this case: the behavior of isinstance can be
>>> customized. It can happen unbeknownst to a user who subclasses a
>>> class that does that.
>>
>> Really? I didn't know that -- how do you do that?
>
>>>> class Type(type):
> ... def __instancecheck__(self, other): return True
> ...
>>>> class A(metaclass=Type): pass
> ...
>>>> class B: pass
> ...
>>>> isinstance(B(), A)
> True
>
> See also
>
> http://www.python.org/dev/peps/pep-3119/#overloading-isinstance-and-issubclass
Ah, ok. Isn't menctioned in the main documentation though.
--
Gabriel Genellina
More information about the Python-list
mailing list