diff --git a/CHANGES.md b/CHANGES.md index 4679a4341..fde06f8fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ master - Ensure that unpickling a function defined in a dynamic module several times sequentially does not reset the values of global variables. ([issue #187](https://github.com/cloudpipe/cloudpickle/issues/205)) +- Restrict the ability to pickle annotations to python3.7+ ([issue #193]( + https://github.com/cloudpipe/cloudpickle/issues/193) and [issue #196](https://github.com/cloudpipe/cloudpickle/issues/196)) 0.5.6 diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index 9b95b3f88..b4ab21baa 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -582,7 +582,7 @@ def save_function_tuple(self, func): 'name': func.__name__, 'doc': func.__doc__, } - if hasattr(func, '__annotations__'): + if hasattr(func, '__annotations__') and sys.version_info >= (3, 7): state['annotations'] = func.__annotations__ if hasattr(func, '__qualname__'): state['qualname'] = func.__qualname__ diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 07b9c5986..dbe9ceb7b 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -1236,7 +1236,9 @@ def g(): self.assertEqual(f2.__doc__, f.__doc__) - @unittest.skipIf(sys.version_info[0] < 3, "This syntax won't work on py2.") + @unittest.skipIf(sys.version_info < (3, 7), + """This syntax won't work on py2 and pickling annotations + isn't supported for py36 and below.""") def test_wraps_preserves_function_annotations(self): from functools import wraps