type(d) != type(d.copy()) when type(d).issubclass(dict)

kj no.email at please.post
Sun Dec 26 13:48:12 EST 2010


In <Xns9E59A27DEF178duncanbooth at 127.0.0.1> Duncan Booth <duncan.booth at invalid.invalid> writes:

>kj <no.email at please.post> wrote:

>> Watch this:
>> 
>>>>> class neodict(dict): pass
>> ... 
>>>>> d = neodict()
>>>>> type(d)
>><class '__main__.neodict'>
>>>>> type(d.copy())
>><type 'dict'>
>> 
>> 
>> Bug?  Feature?  Genius beyond the grasp of schlubs like me? 

>Feature.

>In (almost?) all cases any objects constructed by a subclass of a builtin 
>class will be of the original builtin class.


What I *really* would like to know is: how do *you* know this (and
the same question goes for the other responders who see this behavior
of dict as par for the course).  Can you show me where it is in
the documentation?  I'd really appreciate it.  TIA!

~kj



More information about the Python-list mailing list