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

Closed as not planned

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

Activity

  1. changed the title [-]`TypeError: cannot pickle '_abc._abc_data' object` when using cloudpickle on CPython 3.14[/-] [+]`TypeError: cannot pickle '_abc._abc_data' object` when using cloudpickle with ABC derived classes with type annotations on CPython 3.14[/+] on Oct 31, 2025
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixes
    3.15bugs and security fixes
    type-bugAn unexpected behavior, bug, or error
    on Oct 31, 2025
  3. picnixz commented on Oct 31, 2025

    @picnixz
    Member
  4. JelleZijlstra commented on Oct 31, 2025

    @JelleZijlstra
    Member

    This is going to be for cloudpickle to figure out; I think it comes with their territory of doing advanced introspection and reconstruction of objects.

    The annotate function added by PEP-649 / PEP-749 comes with a closure that contains a reference back to the class dict. Presumably to solve this, cloudpickle should detect that the dict in this closure is the same as the class dict, and avoid trying to serialize it again.

  5. ogrisel commented on Oct 31, 2025

    @ogrisel
    ContributorAuthor

    Thanks for the hint. It is curious that the builtin memoization mechanism of the pickler does not handle that automatically for us, but I guess the devil is in the details. We will investigate on the cloudpickle side. Let me close here.

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

    3.14bugs and security fixes3.15bugs 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