Skip to content

typing.Generic-based type annotations cannot be loaded #196

Description

@marcbllv

Cloud pickle 0.5.5 now supports pickling of type annotations, but some of them cannot be pickled and loaded. Especially generic types that are based on base class Generic, like Sequence, Tuple, List, ...

Here is the issue:

importtypingimportcloudpicklecloudpickle.loads(cloudpickle.dumps(typing.Sequence[int]))
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/Users/marcbeillevaire/anaconda/envs/test/lib/python3.6/typing.py", line948, in__new__raiseTypeError("Cannot inherit from plain Generic")
TypeError: CannotinheritfromplainGeneric

Note that this works fine:

importtypingimportcloudpicklecloudpickle.loads(cloudpickle.dumps(typing.Sequence)) # Sequence, not Sequence[int]

It looks like the arguments of __getitem__ get lost, and only the generic class is pickled -- here: Sequence, and not Sequence[int].

This leads to loading a class that inherits from typing.Generic, not typing.Generic[int] which raises the error (see typing.py line 948 where the error above is raised).

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