[New-bugs-announce] [issue18195] error when deep copying module is confusing

mrjbq7 report at bugs.python.org
Wed Jun 12 00:45:32 CEST 2013


New submission from mrjbq7:

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,

----------
messages: 190996
nosy: mrjbq7
priority: normal
severity: normal
status: open
title: error when deep copying module is confusing

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18195>
_______________________________________


More information about the New-bugs-announce mailing list