Skip to content

Commit 3972628

Browse files
jdufresnerhettinger
authored andcommitted
bpo-30296 Remove unnecessary tuples, lists, sets, and dicts (#1489)
* Replaced list(<generator expression>) with list comprehension * Replaced dict(<generator expression>) with dict comprehension * Replaced set(<list literal>) with set literal * Replaced builtin func(<list comprehension>) with func(<generator expression>) when supported (e.g. any(), all(), tuple(), min(), & max())
1 parent 906f533 commit 3972628

File tree

19 files changed

+32
-39
lines changed

19 files changed

+32
-39
lines changed

Lib/_weakrefset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,19 @@ def issubset(self, other):
157157
__le__ = issubset
158158

159159
def __lt__(self, other):
160-
return self.data < set(ref(item) for item in other)
160+
return self.data < set(map(ref, other))
161161

162162
def issuperset(self, other):
163163
return self.data.issuperset(ref(item) for item in other)
164164
__ge__ = issuperset
165165

166166
def __gt__(self, other):
167-
return self.data > set(ref(item) for item in other)
167+
return self.data > set(map(ref, other))
168168

169169
def __eq__(self, other):
170170
if not isinstance(other, self.__class__):
171171
return NotImplemented
172-
return self.data == set(ref(item) for item in other)
172+
return self.data == set(map(ref, other))
173173

174174
def symmetric_difference(self, other):
175175
newset = self.copy()

Lib/distutils/msvc9compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def query_vcvarsall(version, arch="x86"):
255255
"""Launch vcvarsall.bat and read the settings from its environment
256256
"""
257257
vcvarsall = find_vcvarsall(version)
258-
interesting = set(("include", "lib", "libpath", "path"))
258+
interesting = {"include", "lib", "libpath", "path"}
259259
result = {}
260260

261261
if vcvarsall is None:

Lib/email/headerregistry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ def groups(self):
369369
@property
370370
def addresses(self):
371371
if self._addresses is None:
372-
self._addresses = tuple([address for group in self._groups
373-
for address in group.addresses])
372+
self._addresses = tuple(address for group in self._groups
373+
for address in group.addresses)
374374
return self._addresses
375375

376376

Lib/inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def classify_class_attrs(cls):
389389

390390
mro = getmro(cls)
391391
metamro = getmro(type(cls)) # for attributes stored in the metaclass
392-
metamro = tuple([cls for cls in metamro if cls not in (type, object)])
392+
metamro = tuple(cls for cls in metamro if cls not in (type, object))
393393
class_bases = (cls,) + mro
394394
all_bases = class_bases + metamro
395395
names = dir(cls)

Lib/logging/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def configure_custom(self, config):
463463
c = self.resolve(c)
464464
props = config.pop('.', None)
465465
# Check for valid identifiers
466-
kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
466+
kwargs = dict((k, config[k]) for k in config if valid_ident(k))
467467
result = c(**kwargs)
468468
if props:
469469
for name, value in props.items():
@@ -726,7 +726,7 @@ def configure_handler(self, config):
726726
config['address'] = self.as_tuple(config['address'])
727727
factory = klass
728728
props = config.pop('.', None)
729-
kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
729+
kwargs = dict((k, config[k]) for k in config if valid_ident(k))
730730
try:
731731
result = factory(**kwargs)
732732
except TypeError as te:

Lib/multiprocessing/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def get_all_start_methods(self):
261261
else:
262262
return ['fork', 'spawn']
263263

264-
DefaultContext.__all__ = list(x for x in dir(DefaultContext) if x[0] != '_')
264+
DefaultContext.__all__ = [x for x in dir(DefaultContext) if x[0] != '_']
265265

266266
#
267267
# Context types for fixed start method

Lib/multiprocessing/forkserver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def ensure_running(self):
9898
if self._preload_modules:
9999
desired_keys = {'main_path', 'sys_path'}
100100
data = spawn.get_preparation_data('ignore')
101-
data = dict((x,y) for (x,y) in data.items()
102-
if x in desired_keys)
101+
data = {x: y for x, y in data.items() if x in desired_keys}
103102
else:
104103
data = {}
105104

Lib/multiprocessing/sharedctypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def synchronized(obj, lock=None, ctx=None):
115115
scls = class_cache[cls]
116116
except KeyError:
117117
names = [field[0] for field in cls._fields_]
118-
d = dict((name, make_property(name)) for name in names)
118+
d = {name: make_property(name) for name in names}
119119
classname = 'Synchronized' + cls.__name__
120120
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
121121
return scls(obj, lock, ctx)

Lib/pathlib.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ class _WindowsFlavour(_Flavour):
114114

115115
is_supported = (os.name == 'nt')
116116

117-
drive_letters = (
118-
set(chr(x) for x in range(ord('a'), ord('z') + 1)) |
119-
set(chr(x) for x in range(ord('A'), ord('Z') + 1))
120-
)
117+
drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
121118
ext_namespace_prefix = '\\\\?\\'
122119

123120
reserved_names = (

Lib/pstats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ def add_callers(target, source):
500500
if func in new_callers:
501501
if isinstance(caller, tuple):
502502
# format used by cProfile
503-
new_callers[func] = tuple([i[0] + i[1] for i in
504-
zip(caller, new_callers[func])])
503+
new_callers[func] = tuple(i[0] + i[1] for i in zip(caller, new_callers[func]))
505504
else:
506505
# format used by profile
507506
new_callers[func] += caller

0 commit comments

Comments
 (0)