Skip to content
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

deepcopy memoryview raises TypeError #95081

Open
stuaxo opened this issue Jul 21, 2022 · 5 comments
Open

deepcopy memoryview raises TypeError #95081

stuaxo opened this issue Jul 21, 2022 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@stuaxo
Copy link

stuaxo commented Jul 21, 2022

Bug report

Calling deepcopy on a memoryview raises a TypeError, this looks similar to bug 82474 #82474

This also breaks BinaryField when using Django Polymorphic

jazzband/django-polymorphic#524
Your environment

  • CPython versions tested on: 3.8, 3.10
  • Operating system and architecture: Ubuntu 21.10
>>> a = memoryview(b'123')
>>> from copy import deepcopy
>>> deepcopy(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'memoryview' object
@stuaxo stuaxo added the type-bug An unexpected behavior, bug, or error label Jul 21, 2022
@corona10
Copy link
Member

corona10 commented Jul 21, 2022

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 #82474 case.

@corona10
Copy link
Member

corona10 commented Jul 21, 2022

@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>

@serhiy-storchaka
Copy link
Member

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.

@corona10
Copy link
Member

corona10 commented Jul 21, 2022

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?
#95082 (comment)

@corona10
Copy link
Member

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 :)

@iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

4 participants