New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error when deep copying module is confusing #62395
Comments
If you have a simple module (say "foo.py"): $ cat foo.py
bar = 1 You get weird errors when trying to deep copy them (which I did by accident, not intentionally trying to deep copy modules): Python 2.7.2: >>> import foo
>>> import copy
>>> copy.deepcopy(foo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
y = callable(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 93, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__() Python 3.3.2: >>> import foo
>>> import copy
>>> copy.deepcopy(foo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.3/copy.py", line 174, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.3/copy.py", line 301, in _reconstruct
y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update' I'm not expecting to be able to deep copy a module, but it would be really great if it is not possible for the error message to say something like "deepcopy doesn't work for modules" rather than two different funky tracebacks that don't really explain the problem... Thanks, |
Well, we don't generally complicate the code to handle edge cases. That said, it might not be too complicated to add copy protocol methods to the module object which just raise a more useful error. |
Python 3.6: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/copy.py", line 97, in copy
rv = reductor(4)
TypeError: can't pickle module objects |
This issue looks as enhancement rather than bug fix. Since it is fixed in 3.6 I'm closing it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: