Skip to content

TypeError: cannot pickle '_abc._abc_data' object when using cloudpickle with ABC derived classes with type annotations on CPython 3.14 #140820

@ogrisel

Description

@ogrisel

I am not sure if this can be considered a regression or not, but the following cloudpickle code that used to work with CPython 3.13 no longer works with CPython 3.14:

from abc import ABC

import cloudpickle

def class_factory():
    class Model(ABC):
        field: int

    return Model

cloudpickle.dumps(class_factory())
"""
TypeError: cannot pickle '_abc._abc_data' object
when serializing dict item '_abc_impl'
when serializing tuple item 0
when serializing cell reconstructor arguments
when serializing cell object
when serializing tuple item 0
when serializing dict item '__closure__'
when serializing tuple item 1
when serializing function state
when serializing function object
when serializing dict item '__annotate_func__'
when serializing tuple item 0
when serializing abc.ABCMeta state
when serializing abc.ABCMeta object
"""

Note that removing the type annotation, e.g. with:

    class Model(ABC):
        field = 0

makes the problem vanish.

Since I have no idea about the internals of _abc._abc_data and how they relate to type annotations, I would appreciate some opinions if this change of behavior of CPython is intended or not and if it is, how we could deal with it in cloudpickle.

Original issue on the cloudpickle tracker: cloudpipe/cloudpickle#572

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesextension-modulesC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions