Skip to content

Unable to pickle abstract class (using abc.ABC) with type annotations #572

Closed

Description

@Viicos

Starting with Python 3.14a3, the following raises a TypeError:

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
"""

Activity

  1. ogrisel commented on Oct 31, 2025

    @ogrisel
    Contributor

    @Viicos thanks for the report. Would you be interested in investigating whether it's possible to add support for this?

  2. Viicos commented on Oct 31, 2025

    @Viicos
    Author

    I reported the issue as I encountered it when adding support for Python 3.14 in Pydantic, and got tests failing. I won't have capacity to look into this.

  3. ogrisel commented on Oct 31, 2025

    @ogrisel
    Contributor

    I opened a mirror issue on CPython since this code used to work with CPython 3.13 and the resulting change of picklability status might not have been intended.

  4. glemaitre commented on Oct 31, 2025

    @glemaitre
    Contributor

    I'll give a shot at it and see where it goes.

  5. ogrisel commented on Oct 31, 2025

    @ogrisel
    Contributor

    Let me try to assign this to copilot to check its capabilities on a real life problem.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions