Skip to content

Undocumented behavior change in pickle: PicklingError raised earlier for local objects in Python 3.14 #139806

@liamhuber

Description

@liamhuber

Summary

pickle has changed from raising an AttributeError to PicklingError for functions containing locals in their reduced path. This change is not reflected in the what's new in 3.14 for pickle.

Example

>>> import pickle
>>> 
>>> def some_function(a, b):
...     def some_inner_function(c, d):
...         return a + b + c + d
...    pickle.dumps(some_inner_function)
>>>
>>> try:
...     some_function(1, 2)
... except AttributeError as e:
...     print(e)
Can't pickle local object 'some_function.<locals>.some_inner_function'

on 3.14 this raises _pickle.PicklingError: Can't pickle local object <function some_function.<locals>.some_inner_function at 0x7fb4fd1a3060>

Cf. the CI in this repo for tests on 3.11-3.14.

Impact

Code that expected and caught AttributeError now gets PicklingError

Python versions

Works in 3.11-3.13, changed in 3.14

Resolution

A comment in the changelog, or a reversion to raising an AttributeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirpendingThe issue will be closed if no feedback is provided

    Projects

    Status

    No status

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions