deepcopy chokes with TypeError on dynamically assigned instance method

Nick Coghlan ncoghlan at iinet.net.au
Sat Feb 12 21:01:42 EST 2005


"@t comcast d.t net <"@bag.python.org wrote:
> As an aside, what is the tuple returned by a reductor called?  What are 
> its components called?

Ya got me. Alex might have a name for it :)

>  >Normally, the methods live in the class dictionary, so they don't cause a
>  >problem with copying the instance.
>  >
> But a dynamically assigned instance method lives in the intance 
> dictionary, making deepcopy choke when it deepcopies the instance state. 
>  That makes sense now.

Yup.

> True.  It wouldn't cause a problem within my __init__, since the 
> attribute is reassigned after the deepcopy, though should anyone else 
> deepcopy an instance...  Definitely better that the deepcopy throws the 
> TypeError.  But why shouldn't we be able to copy a non-method function?

I honestly don't know, although I'm hard-pressed to see how doing so would ever 
be *useful*. Duplicating *parts* of a function would seem to make sense (to 
build a new function which is similar, but not identical), but duplicating the 
whole thing seems rather pointless. Although I guess you could just pickle it 
and then unpickle the result to make a copy :)

Again, Alex Martelli or someone else more familiar with the guts of copy.py than 
I am might be able to give a better answer if they happen to see the question.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list