8000 "pickle.Unpickler.persistent_load" and "pickle.Pickler.persistent_id" became read-only in python 3.13 · Issue #125631 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
"pickle.Unpickler.persistent_load" and "pickle.Pickler.persistent_id" became read-only in python 3.13 #125631
Closed
@jcea

Description

@jcea

Bug report

Bug description:

In Python releases previous to 3.13, the following code used to work (this idiom is used in Durus and ZODB persistence systems):

Python 3.12.7 (main, Oct  3 2024, 03:21:52) [GCC 10.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pickle import Unpickler
>>> a=Unpickler(open('/dev/zero'))  
>>> a.persistent_load=lambda x: x
>>> 

Fine so far.

In Python 3.13, this doesn't work anymore:

Python 3.13.0 (main, Oct  9 2024, 14:54:06) [GCC 10.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pickle import Unpickler
>>> a=Unpickler(open('/dev/zero'))
>>> a.persistent_load=lambda x: x
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    a.persistent_load=lambda x: x
    ^^^^^^^^^^^^^^^^^
AttributeError: '_pickle.Unpickler' object attribute 'persistent_load' is read-only

I don't know if this is an intended change or a regression.

PS: The subclass approach works:

Python 3.13.0 (main, Oct  9 2024, 14:54:06) [GCC 10.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pickle import Unpickler
>>> def x(Unpickler):
...     def persistent_load(self, x):
...         return x
...         
>>> b=x(open("/dev/zero"))
>>> 

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0