isinstance() and multiple inheritance/ctypes

Chris Angelico rosuav at gmail.com
Thu Aug 27 23:25:48 EDT 2015


On Fri, Aug 28, 2015 at 1:02 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, 28 Aug 2015 12:33 am, Chris Angelico wrote:
>
>> On Thu, Aug 27, 2015 at 10:59 PM, Steven D'Aprano <steve at pearwood.info>
>> wrote:
>>> On Thu, 27 Aug 2015 09:14 am, Chris Angelico wrote:
>>>
>>>> On Thu, Aug 27, 2015 at 9:12 AM, Chris Angelico <rosuav at gmail.com>
>>>> wrote:
>>>>> Or is there a magic __isinstance__
>>>>
>>>> Argh, keyed the wrong thing and sent the post prematurely. Meant to say:
>>>>
>>>> Or is there a magic __instancecheck__ method somewhere that I'm not
>>>> aware of?
>>>
>>> Yes -- see Terry Reedy's post.
>>>
>>> isinstance(inst, klass) ends up calling
>>>
>>> type(klass).__instancecheck__(klass, inst)
>>
>> I'm aware that it _can_ exist, but I was asking if one _did_ exist.
>
>
> Er, I'm still not getting you. Of course one exists, otherwise isinstance
> would end up raising an exception.
>
> py> type.__instancecheck__
> <method '__instancecheck__' of 'type' objects>
>
> What am I missing?

Hi, I'm trying to figure out why my object is coming out as an
instance of list, when it shouldn't be.

1) Is it really the object you think it is?
2) Does that type of object define __instancecheck__?

There are certain normal, default expectations. We all know what those
are. I was asking if these expectations had been modified in any way.

ChrisA



More information about the Python-list mailing list