-
Notifications
You must be signed in to change notification settings - Fork 167
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
Fix #71: make cloudpickle Python 3.6 compatible #72
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4945361
Fix #71: make cloudpickle Python 3.6 compatible
pitrou 78c68eb
Fixes for 2.6 and pypy
pitrou 020f477
Put the cache at a strategically better place
pitrou a910ab5
Fix cache on PyPy
pitrou e26a76f
Add a test for EXTENDED_ARG
pitrou 319ece0
Try to fix 2.6 and pypy
pitrou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import pytest | ||
import pickle | ||
import sys | ||
import random | ||
import functools | ||
import itertools | ||
import platform | ||
|
@@ -333,6 +334,32 @@ def g(y): | |
res = loop.run_sync(functools.partial(g2, 5)) | ||
self.assertEqual(res, 7) | ||
|
||
def test_extended_arg(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! |
||
# Functions with more than 65535 global vars prefix some global | ||
# variable references with the EXTENDED_ARG opcode. | ||
nvars = 65537 + 258 | ||
names = ['g%d' % i for i in range(1, nvars)] | ||
r = random.Random(42) | ||
d = dict([(name, r.randrange(100)) for name in names]) | ||
# def f(x): | ||
# x = g1, g2, ... | ||
# return zlib.crc32(bytes(bytearray(x))) | ||
code = """ | ||
import zlib | ||
|
||
def f(): | ||
x = {tup} | ||
return zlib.crc32(bytes(bytearray(x))) | ||
""".format(tup=', '.join(names)) | ||
exec(textwrap.dedent(code), d, d) | ||
f = d['f'] | ||
res = f() | ||
data = cloudpickle.dumps([f, f]) | ||
d = f = None | ||
f2, f3 = pickle.loads(data) | ||
self.assertTrue(f2 is f3) | ||
self.assertEqual(f2(), res) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.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.
Can you think of a good test that would cover this branch?
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.
Not really. You would need a function using a huge number of constants.
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.
Actually, we can generate that function.