Skip to content

PicklingError on CPython 3.14.0 when using functools.update_wrapper and a type annotated function #143067

@ogrisel

Description

@ogrisel

Bug report

Bug description:

The following minimal reproducer used to run without exception with CPython 3.13 and earlier but started to fail with CPython 3.14.0.

The problem only happens with the third call to dumps, hence is related to the combinations of functools.update_wrapper and a type annotated function.

from functools import update_wrapper
from pickle import dumps


class _FuncWrapper:
    def __init__(self, function):
        self.function = function
        update_wrapper(self, self.function)


def some_function_without_annotations(x):
    return x


def some_function_with_annotations(x: str) -> str:
    return x


dumps(some_function_with_annotations)  # ok
dumps(_FuncWrapper(some_function_without_annotations))  # ok
dumps(_FuncWrapper(some_function_with_annotations))  # raises
---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)
Cell In[0], line 22
     20 dumps(some_function_with_annotations)
     21 dumps(_FuncWrapper(some_function_without_annotations))
---> 22 dumps(_FuncWrapper(some_function_with_annotations))

PicklingError: Can't pickle <function __annotate__ at 0x108351170>: it's not the same object as __main__.__annotate__
when serializing dict item '__annotate__'
when serializing _FuncWrapper state
when serializing _FuncWrapper object

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions