Skip to content

Pickling generic annotations errors #317

@valtron

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)

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