Skip to content

Python 3.5/3.6 Functions with Type Hints are lost #171

Description

@achapkowski

Let's say I have a simple function:

import cloudpickle
import typing, inspect
def add(x: int=1,y: int=2 ) -> int:
return x+y

It runs as expected:

>>> add()
3
>>> print(typing.get_type_hints(add))
{'x': <class 'int'>, 'return': <class 'int'>, 'y': <class 'int'>}

Now if I pickle it, then unpickle the function, I lose the annotation for the typing.

>>> f = cloudpickle.loads(cloudpickle.dumps(add))
>>> print(typing.get_type_hints(f))
{}
>>> f()
3

So when a method is pickled/unpickled the typing is dropped. Is there anyway to include typing in the pickling process? It helps with introspection of a user's method when you send it someplace else.

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