getting special from type, not instance (was Re: [Python-Dev] copy confusion)

Alex Martelli aleax at aleax.it
Fri Jan 14 00:26:02 CET 2005


On 2005 Jan 14, at 00:11, Guido van Rossum wrote:

>>> Let's do override descriptors.
>>
>> A Pronouncement!!!
>>
>>> And please, someone fix copy.py in 2.3 and 2.4.
>>
>> Sure -- what way, though?  The way I proposed in my last post about 
>> it?
>
> This would do it, right? (From your first post in this conversation
> according to gmail:)
>
>> Armin's fix was to change:
>>
>>     conform = getattr(type(obj), '__conform__', None)
>>
>> into:
>>
>>     for basecls in type(obj).__mro__:
>>         if '__conform__' in basecls.__dict__:
>>             conform = basecls.__dict__['__conform__']
>>             break
>>     else:
>>         # not found

Yes, the code could be expanded inline each time it's needed (for 
__copy__, __getstate__, and all other special methods copy.py needs to 
get-from-the-type).  It does seem better to write it once as a private 
function of copy.py, though.

Plus, to fix the effbot's bug, we need to have in function copy() a 
test about object type that currently is in deepcopy() [[for the 
commented purpose of fixing a problem with Boost's old version -- but 
it works to make deepcopy work in the effbot's case too]] but not in 
copy().  Lastly, the tests should also be enriched to make sure they 
catch the bug (no doc change needed, it seems to me).

I can do it this weekend if the general approach is OK, since Clark has 
kindly agreed to do the next rewrite of PEP 246;-).


Alex



More information about the Python-Dev mailing list