Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 195
Fix cloudpickle incompatibilities on early Python 3.5 versions#361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
fcbce90
fix basic incompatibilities with old Python3.5
pierreglaser 3fa3227
fix pickling of type hints in Python 3.5.[0-2]
pierreglaser 732343e
modify typing test to account for Python 3.5.[0-2]
pierreglaser 3adc5be
fixup! fix pickling of type hints in Python 3.5.[0-2]
pierreglaser d2b8aa6
fixup! fix pickling of type hints in Python 3.5.[0-2]
pierreglaser 96c1d2f
update changelog
pierreglaser 7996513
fix mistake in parametrized type hint checker
pierreglaser f164a29
try to test cloudpickle agains Python 3.5.0 in CI
pierreglaser a7e521f
try to use conda python in the CI
pierreglaser 2c13f90
Merge branch 'master' into cloudpickle-py350
ogrisel 4af5e8d
fixup! try to use conda python in the CI
pierreglaser 47d981a
Merge branch 'cloudpickle-py350' of github.com:pierreglaser/cloudpick…
pierreglaser 2c9e644
debug miniconda
pierreglaser d5e0586
fixup! debug miniconda
pierreglaser f50f87f
fixup! fixup! debug miniconda
pierreglaser 726d86d
fixup! fixup! debug miniconda
pierreglaser 0d834ce
fixup! fixup! fixup! debug miniconda
pierreglaser 405b99a
a few last tries
pierreglaser b1eca25
fixup! a few last tries
pierreglaser abd46d7
I think I get it
pierreglaser 1fb09a0
rollback CI changes
pierreglaser 736127c
fix some Python version check
pierreglaser 6e3621d
this cannot be done using version checks
pierreglaser ec41dee
this cannot be done using version checks
pierreglaser ae643fb
fix typing_extension tests for early Python 3.5
pierreglaser a9dadd6
revert TypeVar tracking
pierreglaser acd23e4
fix sys version checks
pierreglaser e573c37
add a few explanations
pierreglaser c9c8b46
Update cloudpickle/cloudpickle.py
ogrisel cf9e42e
Re-enable dynamic TypeVar tracking
ogrisel 8c030a3
Apply suggestions from code review
ogrisel 6359bc5
be more explicit when testing Final/Literal
pierreglaser e58c34b
Workaround for Python 3.5.3
ogrisel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2047,6 +2047,9 @@ def test_pickle_dynamic_typevar(self): | ||
| for attr in attr_list: | ||
| assert getattr(T, attr) == getattr(depickled_T, attr) | ||
| @pytest.mark.skipif( | ||
| sys.version_info[:3] == (3, 5, 3), | ||
| reason="TypeVar instances are not weakref-able in Python 3.5.3") | ||
| def test_pickle_dynamic_typevar_tracking(self): | ||
| T = typing.TypeVar("T") | ||
| T2 = subprocess_pickle_echo(T, protocol=self.protocol) | ||
| @@ -2081,20 +2084,32 @@ class C(typing.Generic[T]): | ||
| with subprocess_worker(protocol=self.protocol) as worker: | ||
| def check_generic(generic, origin, type_value): | ||
| def check_generic(generic, origin, type_value, use_args): | ||
| assert generic.__origin__ is origin | ||
| assert len(generic.__args__) == 1 | ||
| assert generic.__args__[0] is type_value | ||
| assert len(origin.__orig_bases__) == 1 | ||
| ob = origin.__orig_bases__[0] | ||
| assert ob.__origin__ is typing.Generic | ||
| if sys.version_info >= (3, 5, 3): | ||
| assert len(origin.__orig_bases__) == 1 | ||
| ob = origin.__orig_bases__[0] | ||
| assert ob.__origin__ is typing.Generic | ||
| else: # Python 3.5.[0-1-2], pragma: no cover | ||
| assert len(origin.__bases__) == 1 | ||
| ob = origin.__bases__[0] | ||
| if use_args: | ||
| assert len(generic.__args__) == 1 | ||
| assert generic.__args__[0] is type_value | ||
| else: | ||
| assert len(generic.__parameters__) == 1 | ||
| assert generic.__parameters__[0] is type_value | ||
| assert len(ob.__parameters__) == 1 | ||
| return "ok" | ||
| assert check_generic(C[int], C, int) == "ok" | ||
| assert worker.run(check_generic, C[int], C, int) == "ok" | ||
| # backward-compat for old Python 3.5 versions that sometimes relies | ||
| # on __parameters__ | ||
| use_args = getattr(C[int], '__args__', ()) != () | ||
| assert check_generic(C[int], C, int, use_args) == "ok" | ||
| assert worker.run(check_generic, C[int], C, int, use_args) == "ok" | ||
| def test_locally_defined_class_with_type_hints(self): | ||
| with subprocess_worker(protocol=self.protocol) as worker: | ||
| @@ -2116,19 +2131,38 @@ def check_annotations(obj, expected_type): | ||
| assert check_annotations(obj, type_) == "ok" | ||
| assert worker.run(check_annotations, obj, type_) == "ok" | ||
| def test_generic_extensions(self): | ||
| def test_generic_extensions_literal(self): | ||
| typing_extensions = pytest.importorskip('typing_extensions') | ||
| objs = [ | ||
| typing_extensions.Literal, | ||
| typing_extensions.Final, | ||
| typing_extensions.Literal['a'], | ||
| typing_extensions.Final[int], | ||
| def check_literal_equal(obj1, obj2): | ||
| assert obj1.__values__ == obj2.__values__ | ||
| assert type(obj1) == type(obj2) == typing_extensions._LiteralMeta | ||
| literal_objs = [ | ||
| typing_extensions.Literal, typing_extensions.Literal['a'] | ||
| ] | ||
| for obj in literal_objs: | ||
| depickled_obj = pickle_depickle(obj, protocol=self.protocol) | ||
| if sys.version_info[:3] >= (3, 5, 3): | ||
| assert depickled_obj == obj | ||
| else: | ||
| # __eq__ does not work for Literal objects in early Python 3.5 | ||
| check_literal_equal(obj, depickled_obj) | ||
| def test_generic_extensions_final(self): | ||
| typing_extensions = pytest.importorskip('typing_extensions') | ||
| def check_final_equal(obj1, obj2): | ||
| assert obj1.__type__ == obj2.__type__ | ||
| assert type(obj1) == type(obj2) == typing_extensions._FinalMeta | ||
| final_objs = [typing_extensions.Final, typing_extensions.Final[int]] | ||
| for obj in objs: | ||
| for obj in final_objs: | ||
| depickled_obj = pickle_depickle(obj, protocol=self.protocol) | ||
| assert depickled_obj == obj | ||
| if sys.version_info[:3] >= (3, 5, 3): | ||
| assert depickled_obj == obj | ||
| else: | ||
| # __eq__ does not work for Final objects in early Python 3.5 | ||
| check_final_equal(obj, depickled_obj) | ||
pierreglaser marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_class_annotations(self): | ||
| class C: | ||
| @@ -2182,21 +2216,26 @@ def _all_types_to_test(): | ||
| class C(typing.Generic[T]): | ||
| pass | ||
| return [ | ||
| types_to_test = [ | ||
| C, C[int], | ||
| T, typing.Any, typing.NoReturn, typing.Optional, | ||
| typing.Generic, typing.Union, typing.ClassVar, | ||
| T, typing.Any, typing.Optional, | ||
| typing.Generic, typing.Union, | ||
| typing.Optional[int], | ||
| typing.Generic[T], | ||
| typing.Callable[[int], typing.Any], | ||
| typing.Callable[..., typing.Any], | ||
| typing.Callable[[], typing.Any], | ||
| typing.Tuple[int, ...], | ||
| typing.Tuple[int, C[int]], | ||
| typing.ClassVar[C[int]], | ||
| typing.List[int], | ||
| typing.Dict[int, str], | ||
| ] | ||
| if sys.version_info[:3] >= (3, 5, 3): | ||
| types_to_test.append(typing.ClassVar) | ||
| types_to_test.append(typing.ClassVar[C[int]]) | ||
| if sys.version_info >= (3, 5, 4): | ||
| types_to_test.append(typing.NoReturn) | ||
| return types_to_test | ||
| if __name__ == '__main__': | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you track
TypeVardefintions anymore? This seems unrelated to the change to support early 3.5.x.Doesn't this change break ant test?
Edit: I see you removed
test_pickle_dynamic_typevar_tracking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also won't this break unpickling objects pickled with cloudpickle 1.4.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TyperVarinstances are not weakreferable inPython 3.5.3..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always restore the
class_tracker_idfor backward compat.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-ran the tests with old Python 3.5.x and they pass...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum you are right they fail just for 3.5.3 ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let me do a workaround for 3.5.3.