classification
Title: pickle.py bytearray memoization bug with protocol 5
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Carl.Friedrich.Bolz, pitrou
Priority: normal Keywords: patch

Created on 2021-04-21 18:08 by Carl.Friedrich.Bolz, last changed 2021-04-23 21:28 by pitrou. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25501 merged Carl.Friedrich.Bolz, 2021-04-21 18:17
Messages (3)
msg391537 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-04-21 18:08
The new codepath for the BYTEARRAY8 bytecode is missing memoization:

>>> import pickletools, pickle
>>> b = (bytearray(b"abc"), ) * 2
>>> b1, b2 = pickle.loads(pickle.dumps(b, 5)) # C version
>>> b1 is b2
True
(bytearray(b'abc'), bytearray(b'abc'))
>>> b1, b2 = pickle.loads(pickle._dumps(b, 5)) # python version
>>> b1 is b2 # :-(
False

Found it because PyPy is using pickle.py with no C implementation. I'm preparing a patch.
msg391737 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2021-04-23 21:27
New changeset 1e9f0933095403b215c2c4a0be7915d034ff7026 by Carl Friedrich Bolz-Tereick in branch 'master':
bpo-43907: add missing memoize call in pure python pickling of bytearray (GH-25501)
https://github.com/python/cpython/commit/1e9f0933095403b215c2c4a0be7915d034ff7026
msg391738 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2021-04-23 21:28
Thanks for the report and fix!
History
Date User Action Args
2021-04-23 21:28:19pitrousetstatus: open -> closed

components: + Library (Lib)
versions: + Python 3.10
messages: + msg391738
type: behavior
resolution: fixed
stage: patch review -> resolved
2021-04-23 21:27:31pitrousetmessages: + msg391737
2021-04-21 18:18:29xtreaksetnosy: + pitrou
2021-04-21 18:17:24Carl.Friedrich.Bolzsetkeywords: + patch
stage: patch review
pull_requests: + pull_request24221
2021-04-21 18:08:15Carl.Friedrich.Bolzcreate