Skip to content

Pickling Annotations can fail #193

@cicdw

Description

@cicdw

Now that cloudpickle is including annotations, there are certain typing classes that fail to pickle in versions of python < 3.7 that are now raising errors when included as annotations:

## python 3.6.6

import typing
import cloudpickle

tt = typing.Union[str, typing.List[str]]
cloudpickle.dumps(tt, protocol=cloudpickle.DEFAULT_PROTOCOL) # always fails
# _pickle.PicklingError: Can't pickle typing.Union[str, typing.List[str]]: it's not the same object as typing.Union

def f(x: tt) -> tt:
    return x

## passes in cloudpickle==0.5.3 because type annotations were ignored
## but fails in 0.5.4+
cloudpickle.dumps(f, protocol=cloudpickle.DEFAULT_PROTOCOL)

All of this works fine in python 3.7

Related: python/typing#511

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