-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Deepcopying property objects results in unexpected TypeError #82474
Comments
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.
Means that property objects will be treated as atomic, and therefore returned as-is. |
A small change: The fix should go to Lib/copy.py:198, not line 208. |
But the property object is not atomic. It's attribute __doc__ is writeable. |
Function objects are considered "atomic" here and I believe you can also write to their __doc__ (among other attributes). |
This bug appears to also affect shallow copies and can be reproduced with the following code: >>> import copy
>>> obj = property()
>>> copy.copy(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 96, in copy
rv = reductor(4)
TypeError: can't pickle property objects |
I can confirm this behavior also on python 3.6 3.8 3.9 |
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: