Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Tools/msi/obj
Tools/ssl/amd64
Tools/ssl/win32
Tools/freeze/test/outdir
/.project
/.pydevproject
Comment on lines +162 to +163
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated change, please revert.


# The frozen modules are always generated by the build so we don't
# keep them in the repo. Also see Tools/build/freeze_modules.py.
Expand Down
4 changes: 2 additions & 2 deletions Lib/_compat_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@
NAME_MAPPING[("multiprocessing", excname)] = ("multiprocessing.context", excname)

# Same, but for 3.x to 2.x
REVERSE_IMPORT_MAPPING = dict((v, k) for (k, v) in IMPORT_MAPPING.items())
REVERSE_IMPORT_MAPPING = {v: k for (k, v) in IMPORT_MAPPING.items()}
assert len(REVERSE_IMPORT_MAPPING) == len(IMPORT_MAPPING)
REVERSE_NAME_MAPPING = dict((v, k) for (k, v) in NAME_MAPPING.items())
REVERSE_NAME_MAPPING = {v: k for (k, v) in NAME_MAPPING.items()}
assert len(REVERSE_NAME_MAPPING) == len(NAME_MAPPING)
Comment on lines -164 to 167
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary. It's just code churn and this is only executed once upon import time.


# Non-mutual mappings.
Expand Down
4 changes: 2 additions & 2 deletions Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3891,14 +3891,14 @@ def __init__(self, prec=None, rounding=None, Emin=None, Emax=None,
if traps is None:
self.traps = dc.traps.copy()
elif not isinstance(traps, dict):
self.traps = dict((s, int(s in traps)) for s in _signals + traps)
self.traps = {s: int(s in traps) for s in _signals + traps}
else:
self.traps = traps

if flags is None:
self.flags = dict.fromkeys(_signals, 0)
elif not isinstance(flags, dict):
self.flags = dict((s, int(s in flags)) for s in _signals + flags)
self.flags = {s: int(s in flags) for s in _signals + flags}
else:
self.flags = flags

Expand Down
4 changes: 2 additions & 2 deletions Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ def get_names(self):

def complete_help(self, *args):
commands = set(self.completenames(*args))
topics = set(a[5:] for a in self.get_names()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I wonder which one would be faster:

  • commands and topics being both sets and then union?
  • using itertools.chain + list(set(...)) directly?
  • using commands.union(topics) where topics is just a generator

Because of all possible changes, I don't think we want to change this. It's just code churn.

if a.startswith('help_' + args[0]))
topics = {a[5:] for a in self.get_names()
if a.startswith('help_' + args[0])}
return list(commands | topics)

def do_help(self, arg):
Expand Down
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ def __call__(self, enumeration):
raise ValueError('aliases found in %r: %s' %
(enumeration, alias_details))
elif check is CONTINUOUS:
values = set(e.value for e in enumeration)
values = {e.value for e in enumeration}
if len(values) < 2:
continue
low, high = min(values), max(values)
Expand Down
4 changes: 2 additions & 2 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,9 +1809,9 @@ def _hierlevel(logger):
# exclude PlaceHolders - the last check is to ensure that lower-level
# descendants aren't returned - if there are placeholders, a logger's
# parent field might point to a grandparent or ancestor thereof.
return set(item for item in d.values()
return {item for item in d.values()
if isinstance(item, Logger) and item.parent is self and
_hierlevel(item) == 1 + _hierlevel(item.parent))
_hierlevel(item) == 1 + _hierlevel(item.parent)}

def __repr__(self):
level = getLevelName(self.getEffectiveLevel())
Expand Down
2 changes: 1 addition & 1 deletion Lib/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def getsignal(signalnum):
@_wraps(_signal.pthread_sigmask)
def pthread_sigmask(how, mask):
sigs_set = _signal.pthread_sigmask(how, mask)
return set(_int_to_enum(x, Signals) for x in sigs_set)
return {_int_to_enum(x, Signals) for x in sigs_set}


if 'sigpending' in _globals:
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ James Tocknell
Bennett Todd
R Lindsay Todd
Eugene Toder
Heikki Toivonen
Erik Tollerud
Stephen Tonkin
Matias Torchinsky
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use dict and set comprehensions when possible
Loading