From 413dc455443855643df7356650f4e397b277f44f Mon Sep 17 00:00:00 2001 From: Chris White Date: Thu, 6 Sep 2018 13:48:26 -0700 Subject: [PATCH 1/2] Remove ability to pickle annotations completely for python3.6 and below --- cloudpickle/cloudpickle.py | 2 +- tests/cloudpickle_test.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index b1107ba92..08dadb9a1 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -566,7 +566,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 f1c3ea55b..949b457c7 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -969,7 +969,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 From 3e514370f7556279fba2ac7a301d552da9d6ac1d Mon Sep 17 00:00:00 2001 From: Chris White Date: Wed, 19 Sep 2018 07:29:40 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) 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