Skip to content

Pickling generic annotations errors #317

Description

@valtron
import typing, cloudpickle
cloudpickle.dumps(typing.Optional[int])

gives:

_pickle.PicklingError: Can't pickle typing.Union[int, NoneType]: it's not the same object as typing.Union

While pickling annotations directly isn't common, this is a problem when trying to pickle a class with annotations whose __module__ == '__main__'. For example, this fails with the same error:

import typing, cloudpickle
class C:
prop: typing.Optional[int]
cloudpickle.dumps(C)

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions