Skip to content

Commit

Permalink
Use set/dict literal syntax (#169)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
alok authored and HyukjinKwon committed May 3, 2018
1 parent 1b1e6ea commit 9a32a6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ 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 _, oparg in _walk_global_ops(co)}

# see if nested function have any global refs
if co.co_consts:
Expand Down
6 changes: 3 additions & 3 deletions tests/cloudpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 9a32a6d

Please sign in to comment.