bug in copy.deepcopy or in getattr or in my understanding?

Peter Otten __peter__ at web.de
Fri Jan 5 09:23:38 EST 2007


Emin wrote:

> Thank you for your reply. As you guessed, I want to be able to select
> the method at runtime as in your final example, but when I tried your
> suggestion I got the same error (see below). I think the problem is
> that getattr is donig something different than in my example where I
> explicitly get it from the dict (see the very end of the transcript
> below):

This has nothing to do with getattr(). You currently can deep-copy
functions, but neither bound nor unbound methods:

>>> import copy
>>> def check(obj):
...     try:
...             copy.deepcopy(obj)
...     except:
...             return "FAILED"
...     return "OK"
...
>>> def function(*args): pass
...
>>> class A:
...     method = function
...
>>> check(function), check(A.method), check(A().method)
('OK', 'FAILED', 'FAILED')

Whether this a bug or a sensible limitation I don't know.

Peter



More information about the Python-list mailing list