This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mrjbq7
Recipients mrjbq7
Date 2013-06-11.22:45:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1370990732.59.0.654966118724.issue18195@psf.upfronthosting.co.za>
In-reply-to
Content
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,
History
Date User Action Args
2013-06-11 22:45:32mrjbq7setrecipients: + mrjbq7
2013-06-11 22:45:32mrjbq7setmessageid: <1370990732.59.0.654966118724.issue18195@psf.upfronthosting.co.za>
2013-06-11 22:45:32mrjbq7linkissue18195 messages
2013-06-11 22:45:32mrjbq7create