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

Duncan Booth duncan.booth at invalid.invalid
Mon Dec 27 07:29:34 EST 2010


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

>>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!
> 

I know it from experience (and reading source). So far as I can tell it 
isn't explicitly stated anywhere in the documentation.

Mostly the documentation just says a method returns 'a copy of' prossibly 
with some modification. For example:

  str.capitalize()
  Return a copy of the string with its first character capitalized and the 
  rest lowercased.

That is ambiguous as it leaves open the question whether it returns "a 
string that is a copy" or an object of the type being operated upon. It 
happens to be the former but it doesn't actually say.


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list