__instancecheck__ metaclasses, how do they work: why do I get True when I tuple, why doesn't print run?

Chris Angelico rosuav at gmail.com
Tue Nov 5 02:18:53 EST 2019


On Tue, Nov 5, 2019 at 5:43 PM dieter <dieter at handshake.de> wrote:
> I suppose that "isinstance" (at least under Python 2) does not
> behave exactly as stated in PEP 3119. Instead, "isinstance"
> first directly checks for the instance to be an instance of the
> class *AND ONLY IF THIS FAILS* calls the class' "__instancecheck__".

PEP 3119 is specifically about Python 3.0; I don't know how much, if
any, was backported into Python 2.

I strongly recommend using Python 3 when probing features like this.
Not everything is supported on the legacy branch of Python.

ChrisA


More information about the Python-list mailing list