[issue38293] Deepcopying property objects results in unexpected TypeError

Guðni Nathan report at bugs.python.org
Fri Sep 27 12:16:43 EDT 2019


New submission from Guðni Nathan <gudni.nathan at gmail.com>:

Currently, attempting to deepcopy a property object will result in an unexpected TypeError:

>>> import copy
>>> obj = property()
>>> new_obj = copy.deepcopy(obj)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1264.0_x64__qbz5n2kfra8p0\lib\copy.py", line 169, in deepcopy
    rv = reductor(4)
TypeError: can't pickle property objects


What I believe is happening here is that since property objects are not treated by the copy module as atomic, they are passed off to be pickled and so our error is raised.
This can be fixed in a similar manner to how it works for type objects, function objects and more.
Adding a single line of code to Lib/copy.py after line 208:

    d[property] = _deepcopy_atomic

Means that property objects will be treated as atomic, and therefore returned as-is.

----------
components: Library (Lib)
messages: 353375
nosy: Guðni Nathan
priority: normal
severity: normal
status: open
title: Deepcopying property objects results in unexpected TypeError
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38293>
_______________________________________


More information about the Python-bugs-list mailing list