python / python/cpython

deepcopy memoryview raises TypeError

Open
#95,081 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

  • 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the deepcopy path in Lib/copy.py shown by the traceback and reproduce the failure with the memoryview example on a supported CPython version. Check related issue 82474 and determine the intended deepcopy behavior for memoryview; done should include coverage for the reported case and no TypeError from deepcopy.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.