Open stuaxo opened 2 years ago
This issue looks like related to https://bugs.python.org/issue22995 and it was intended not to support deepcopy/copy. But I may need to understand the difference between https://github.com/python/cpython/issues/82474 case.
@serhiy-storchaka Is there any reason to prohibit copy.deepcopy/copy
operations for memoryview
object while allowing property
object?
>>> import pickle
>>> import copy
>>> a = property()
>>> pickle.dumps(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot pickle 'property' object
>>> copy.copy(a)
<property object at 0x101017230>
>>> copy.deepcopy(a)
<property object at 0x101017230>
There are no reasons to prohibit shallow and deep copying of memoryview
objects (or I do not know them). And I have not found any mention of memoryview
objects in https://bugs.python.org/issue22995. Could you explain what did you mean? Did you mean some other issue?
By default, shallow and deep copying use the same mechanism as pickling. If pickling works, copying works automatically, if pickling is impossible, copying does not work by default. But if it is possible to make a copy, it can be implemented explicitly using other mechanisms.
There are no reasons to prohibit shallow and deep copying of memoryview objects (or I do not know them). And I have not found any mention of memoryview objects in https://bugs.python.org/issue22995. Could you explain what did you mean? Did you mean some other issue?
I found the related patch from that issue, Can you please take a look at this comment? https://github.com/python/cpython/pull/95082#discussion_r926287551
By default, shallow and deep copying use the same mechanism as pickling. If pickling works, copying works automatically, if pickling is impossible, copying does not work by default. But if it is possible to make a copy, it can be implemented explicitly using other mechanisms.
Okay Thank you for explain :)
Bug report
Calling deepcopy on a memoryview raises a TypeError, this looks similar to bug 82474 https://github.com/python/cpython/issues/82474
This also breaks BinaryField when using Django Polymorphic
https://github.com/django-polymorphic/django-polymorphic/issues/524 Your environment