Skip to content

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

Closed

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

Linked PRs

Activity

  1. StanFromIreland commented on Oct 8, 2025

    @StanFromIreland
    Member

    Seems like a result of b2a8c38, cc @serhiy-storchaka

  2. serhiy-storchaka commented on Oct 8, 2025

    @serhiy-storchaka
    Member

    The Python implementation already raised PicklingError in this example. #122311 unified and improved pickle errors. You can find it in the full changelog, but I think that this change is not significant to be added in What's New.

  3. added
    pendingThe issue will be closed if no feedback is provided
    on Oct 8, 2025
  4. picnixz commented on Oct 9, 2025

    @picnixz
    Member

    Considering it's part of the full changelog, I also believe it's fine not to document it in What's New. As a user, I would actually expect PicklingError instead of AttributeError. However, we could add it in "Porting to Python 3.14" as it appears users were catching those exceptions. The docs say are quite vague though, saying that we can many different exception types during unpickling but not during pickling (omission? deliberate?)

  5. removed
    pendingThe issue will be closed if no feedback is provided
    on Jul 18, 2026
  6. added a commit that references this issue on Jul 19, 2026
  7. added 2 commits that reference this issue on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions