
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2019-09-27 16:16 byGudniNatan, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 16438 | merged | GudniNatan,2019-09-27 19:13 | |
| PR 17968 | merged | miss-islington,2020-01-12 17:42 | |
| PR 17969 | merged | miss-islington,2020-01-12 17:45 | |
| Messages (9) | |||
|---|---|---|---|
| msg353375 -(view) | Author: Guðni Nathan (GudniNatan)* | Date: 2019-09-27 16:16 | |
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 objectsWhat 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 toLib/copy.py after line 208: d[property] = _deepcopy_atomicMeans that property objects will be treated as atomic, and therefore returned as-is. | |||
| msg353376 -(view) | Author: Guðni Nathan (GudniNatan)* | Date: 2019-09-27 16:19 | |
A small change:The fix should go toLib/copy.py:198, not line 208. | |||
| msg353377 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2019-09-27 16:48 | |
But the property object is not atomic. It's attribute __doc__ is writeable. | |||
| msg353383 -(view) | Author: Guðni Nathan (GudniNatan)* | Date: 2019-09-27 17:27 | |
Function objects are considered "atomic" here and I believe you can also write to their __doc__ (among other attributes). | |||
| msg353388 -(view) | Author: Guðni Nathan (GudniNatan)* | Date: 2019-09-27 18:40 | |
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 | |||
| msg353428 -(view) | Author: Emmanuel Arias (eamanu)* | Date: 2019-09-27 23:55 | |
I can confirm this behavior also on python 3.6 3.8 3.9 | |||
| msg359857 -(view) | Author: miss-islington (miss-islington) | Date: 2020-01-12 17:42 | |
New changeset9f3fc6c5b4993f2b362263b494f84793a21aa073 by Miss Islington (bot) (Guðni Natan Gunnarsson) in branch 'master':bpo-38293: Allow shallow and deep copying of property objects (GH-16438)https://github.com/python/cpython/commit/9f3fc6c5b4993f2b362263b494f84793a21aa073 | |||
| msg359860 -(view) | Author: miss-islington (miss-islington) | Date: 2020-01-12 18:00 | |
New changeset4be97260351f214d3c8b8477682323bb52ee2af3 by Miss Islington (bot) in branch '3.7':bpo-38293: Allow shallow and deep copying of property objects (GH-16438)https://github.com/python/cpython/commit/4be97260351f214d3c8b8477682323bb52ee2af3 | |||
| msg359861 -(view) | Author: miss-islington (miss-islington) | Date: 2020-01-12 18:04 | |
New changeset3043ec7d6aed402218404c25179e734166c7fbe0 by Miss Islington (bot) in branch '3.8':bpo-38293: Allow shallow and deep copying of property objects (GH-16438)https://github.com/python/cpython/commit/3043ec7d6aed402218404c25179e734166c7fbe0 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:20 | admin | set | github: 82474 |
| 2020-01-12 18:04:21 | miss-islington | set | messages: +msg359861 |
| 2020-01-12 18:00:30 | miss-islington | set | messages: +msg359860 |
| 2020-01-12 17:45:35 | miss-islington | set | pull_requests: +pull_request17377 |
| 2020-01-12 17:43:50 | cheryl.sabella | set | status: open -> closed stage: patch review -> resolved resolution: fixed versions: - Python 3.6 |
| 2020-01-12 17:42:12 | miss-islington | set | pull_requests: +pull_request17376 |
| 2020-01-12 17:42:04 | miss-islington | set | nosy: +miss-islington messages: +msg359857 |
| 2019-09-27 23:55:53 | eamanu | set | messages: +msg353428 versions: + Python 3.6, Python 3.8, Python 3.9 |
| 2019-09-27 23:38:45 | eamanu | set | nosy: +eamanu |
| 2019-09-27 19:13:27 | GudniNatan | set | keywords: +patch stage: patch review pull_requests: +pull_request16016 |
| 2019-09-27 18:40:01 | GudniNatan | set | messages: +msg353388 |
| 2019-09-27 17:27:23 | GudniNatan | set | messages: +msg353383 |
| 2019-09-27 16:48:27 | serhiy.storchaka | set | nosy: +serhiy.storchaka messages: +msg353377 |
| 2019-09-27 16:19:13 | GudniNatan | set | messages: +msg353376 |
| 2019-09-27 16:16:43 | GudniNatan | create | |