Skip to content

Fix Python 3.14 update_wrapper pickling with lazy annotations#594

Open
BioGeek wants to merge 1 commit into
cloudpipe:masterfrom
BioGeek:python3.14
Open

Fix Python 3.14 update_wrapper pickling with lazy annotations#594
BioGeek wants to merge 1 commit into
cloudpipe:masterfrom
BioGeek:python3.14

Conversation

@BioGeek

@BioGeek BioGeek commented Jun 8, 2026

Copy link
Copy Markdown

Fixes #585.

Python 3.14 adds __annotate__ to functools.WRAPPER_ASSIGNMENTS, so functools.update_wrapper can copy a wrapped callable’s lazy annotation function onto wrapper instances. When the wrapped callable is a method on an annotated ABC, that copied __annotate__ can close over the class dict and reach _abc_impl, causing:

TypeError: cannot pickle '_abc._abc_data' object

This PR detects the specific redundant __annotate__ copied from __wrapped__ and removes it from the object reduction state before pickling.

Changes

  • Strip copied __annotate__ from wrapper instance state when it is identical to __wrapped__.__annotate__.
  • Add a stdlib-only regression test using abc and functools.update_wrapper.
  • Add a changelog entry.

Validation

Tested the original skore==0.11.4 / scikit-learn==1.8.0 reproducer on CPython 3.14.3.

Full test suite:

  • CPython 3.14.3: 265 passed, 13 skipped, 2 xfailed
  • CPython 3.15.0a7: 265 passed, 13 skipped, 2 xfailed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: cannot pickle '_abc._abc_data' object with python 3.14 and cloudpickle 3.1.2

1 participant