Skip to content

Commit 9a32a6d

Browse files
alokHyukjinKwon
authored andcommitted
Use set/dict literal syntax (#169)
* Use set/dict literal syntax Every supported version can use this syntax, and it's both faster and clearer. * Fix indentation and drop unused argument The `op` arg isn't used for creating `out_names`, so we elide it.
1 parent 1b1e6ea commit 9a32a6d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

cloudpickle/cloudpickle.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ def extract_code_globals(cls, co):
578578
# PyPy "builtin-code" object
579579
out_names = set()
580580
else:
581-
out_names = set(names[oparg]
582-
for op, oparg in _walk_global_ops(co))
581+
out_names = {names[oparg] for _, oparg in _walk_global_ops(co)}
583582

584583
# see if nested function have any global refs
585584
if co.co_consts:

tests/cloudpickle_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def g():
222222

223223
def test_unhashable_closure(self):
224224
def f():
225-
s = set((1, 2)) # mutable set is unhashable
225+
s = {1, 2} # mutable set is unhashable
226226

227227
def g():
228228
return len(s)
@@ -494,7 +494,7 @@ def test_extended_arg(self):
494494
nvars = 65537 + 258
495495
names = ['g%d' % i for i in range(1, nvars)]
496496
r = random.Random(42)
497-
d = dict([(name, r.randrange(100)) for name in names])
497+
d = {name: r.randrange(100) for name in names}
498498
# def f(x):
499499
# x = g1, g2, ...
500500
# return zlib.crc32(bytes(bytearray(x)))
@@ -693,7 +693,7 @@ def __init__(self, x):
693693
self.assertEqual(depickled3.x, 3)
694694
self.assertEqual(len(weakset), 2)
695695

696-
self.assertEqual(set(weakset), set([depickled1, depickled2]))
696+
self.assertEqual(set(weakset), {depickled1, depickled2})
697697

698698
def test_faulty_module(self):
699699
for module_name in ['_faulty_module', '_missing_module', None]:

0 commit comments

Comments
 (0)