Skip to content

Pickling Annotations can _still_ fail #209

Closed

Description

@jamesstidard

I'm getting some strange behaviour related to #193. Sorry to open the typing can of worms.

I'm using Python 3.7 and cloudpickle==0.5.6 but have been using cloudpickle via distributed==1.23.2. Which I reported over at: dask/distributed#2291

The above code sample works for me. However, the following does not:

from typing import Optional
from distributed import Client

def f2() -> Optional[int]:
    return 1

def f1() -> int:
    return 1

def main():
    client = Client()
    print(client.submit(f1).result())  # works. prints 1
    print(client.submit(f2).result())  # fail. raises
    client.close()

if __name__ == '__main__':
    main()

Apologies that this includes a dask dependency. I tried to reproduce with the above code snippet but I don't get an exception:

from typing import Optional
import cloudpickle

cloudpickle.dumps(Optional[int], protocol=cloudpickle.DEFAULT_PROTOCOL)

I'm a little bemused to where the problem is coming from now with those results.

Activity

  1. cicdw commented on Oct 5, 2018

    @cicdw
    Contributor

    Just an FYI: distributed is not related, the error occurs on loads:

    import cloudpickle
    
    cloudpickle.loads(cloudpickle.dumps(type(None), protocol=cloudpickle.DEFAULT_PROTOCOL)) # raises
  2. jamesstidard commented on Oct 5, 2018

    @jamesstidard
    Author

    @cicdw ah, yes. Silly me.

  3. ogrisel commented on Oct 5, 2018

    @ogrisel
    Contributor

    Even simpler:

    >>> import pickle, cloudpickle
    >>> pickle.loads(cloudpickle.dumps(type(None)))
    Traceback (most recent call last):
      File "<ipython-input-13-117c2f521d83>", line 1, in <module>
        pickle.loads(cloudpickle.dumps(type(None)))
    AttributeError: type object 'NoneType' has no attribute '__bool__'

    It works with the default pickle:

    >>> pickle.loads(pickle.dumps(type(None)))
    <class 'NoneType'>
  4. added a commit that references this issue on Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions