You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implementing __getattr__ breaks copy and deepcopy #63563
Activity
KassymDorsel commentedon Oct 23, 2013
When __getattr__ is implemented without also implementing __copy__ and __deepcopy__ trying to (deep)copy the class fails.
The copy module checks if a class has implemented __copy__ using hasattr:
An easy fix would be to use:
In Python 3 this change has already been made.
ericsnowcurrently commentedon Oct 24, 2013
Your example worked correctly, since the copy module is indeed not copiable. :) Did you mean "from copy import copy"?
KassymDorsel commentedon Oct 25, 2013
Yes. You're correct. Sorry for the confusion. Below is an updated snippet of code.
ericsnowcurrently commentedon Oct 25, 2013
I knew this sounded familiar. Take a look at bpo-16251.