In my code I'm trying to take copies of instances a class using copy.deepcopy
. The problem is that under some circumstances it is erroring with the following error:
TypeError: 'object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()'
After much digging I have found that I am able to reproduce the error using the following code:
import copy
copy.deepcopy(__builtins__)
The problem appears to be that at some point it is trying to copy the NotImplementedType
builtin. The question is why is it doing this? I have not overridden __deepcopy__
in my class and it doesn't happen all the time. Does anyone have any tips for tracking down where the request to make a copy of this type comes from?
I've put some debugging code in the copy
module itself to ensure that this is what's happening, but the point at which the problem occurs is so far down a recursive stack it's very hard to make much of what I'm seeing.