deepcopy raises TypeError for method/function?

Alex Martelli aleaxit at
Thu Sep 9 23:07:20 CEST 2004

OKB (not okblacke) <BrenBarn at> wrote:
> deepcopy(SomeClass) just silently returns the same SomeClass object.  I
> would expect deepcopy(someObj.someMethod) to do likewise, just returning
> the same method object.
>       Does anyone have any pointers on this?  It seems that certain types
> are safe to deepcopy (even if they're not actually copied) whereas 
> others are not.  Do I just have to manually typecheck for functions and
> methods?  Are there any other types that might raise such an error?

You can use copy_reg to register an identity function as the way to
'copy' function and methods, if that floats your boat.  And sure, there
are other types that raise errors, imagine copying a file object, a
socket, ...!


More information about the Python-list mailing list