From d006b60182f09eb87f44d3138396ea886848893b Mon Sep 17 00:00:00 2001 From: Alok Singh Date: Sun, 29 Apr 2018 22:37:21 -0700 Subject: [PATCH 1/2] Use set/dict literal syntax Every supported version can use this syntax, and it's both faster and clearer. --- cloudpickle/cloudpickle.py | 4 ++-- tests/cloudpickle_test.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index 7eb4552df..e71b24846 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -578,8 +578,8 @@ def extract_code_globals(cls, co): # PyPy "builtin-code" object out_names = set() else: - out_names = set(names[oparg] - for op, oparg in _walk_global_ops(co)) + out_names = {names[oparg] + for op, oparg in _walk_global_ops(co)} # see if nested function have any global refs if co.co_consts: diff --git a/tests/cloudpickle_test.py b/tests/cloudpickle_test.py index 9991d98c7..2ca554442 100644 --- a/tests/cloudpickle_test.py +++ b/tests/cloudpickle_test.py @@ -222,7 +222,7 @@ def g(): def test_unhashable_closure(self): def f(): - s = set((1, 2)) # mutable set is unhashable + s = {1, 2} # mutable set is unhashable def g(): return len(s) @@ -494,7 +494,7 @@ def test_extended_arg(self): 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]) + d = {name: r.randrange(100) for name in names} # def f(x): # x = g1, g2, ... # return zlib.crc32(bytes(bytearray(x))) @@ -693,7 +693,7 @@ def __init__(self, x): self.assertEqual(depickled3.x, 3) self.assertEqual(len(weakset), 2) - self.assertEqual(set(weakset), set([depickled1, depickled2])) + self.assertEqual(set(weakset), {depickled1, depickled2}) def test_faulty_module(self): for module_name in ['_faulty_module', '_missing_module', None]: From cd37e8036d3eeb7683c5d71849a4eff3f2285a34 Mon Sep 17 00:00:00 2001 From: Alok Singh Date: Mon, 30 Apr 2018 16:07:42 -0700 Subject: [PATCH 2/2] Fix indentation and drop unused argument The `op` arg isn't used for creating `out_names`, so we elide it. --- cloudpickle/cloudpickle.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloudpickle/cloudpickle.py b/cloudpickle/cloudpickle.py index e71b24846..61168175c 100644 --- a/cloudpickle/cloudpickle.py +++ b/cloudpickle/cloudpickle.py @@ -578,8 +578,7 @@ def extract_code_globals(cls, co): # PyPy "builtin-code" object out_names = set() else: - out_names = {names[oparg] - for op, oparg in _walk_global_ops(co)} + out_names = {names[oparg] for _, oparg in _walk_global_ops(co)} # see if nested function have any global refs if co.co_consts: