diff --git a/.gitignore b/.gitignore index e234d86e8d5532..4a90254742e4a6 100644 --- a/.gitignore +++ b/.gitignore @@ -159,6 +159,8 @@ Tools/msi/obj Tools/ssl/amd64 Tools/ssl/win32 Tools/freeze/test/outdir +/.project +/.pydevproject # 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. diff --git a/Lib/_compat_pickle.py b/Lib/_compat_pickle.py index a981326432429b..9e0d397b512cee 100644 --- a/Lib/_compat_pickle.py +++ b/Lib/_compat_pickle.py @@ -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) # Non-mutual mappings. diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index ef889ea0cc834c..6df9f61cadf3c3 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -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 diff --git a/Lib/cmd.py b/Lib/cmd.py index 51495fb32160b0..0cccb6d4f5fc9c 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -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() - 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): diff --git a/Lib/enum.py b/Lib/enum.py index 15dddf6de69268..c38c10ee4da2d5 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -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) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 39689a57e6ecd6..3bcedc165ad812 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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()) diff --git a/Lib/signal.py b/Lib/signal.py index c8cd3d4f597ca5..b9ca22bcac30e8 100644 --- a/Lib/signal.py +++ b/Lib/signal.py @@ -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: diff --git a/Misc/ACKS b/Misc/ACKS index 671fcf88c75af9..63ddfb89071c0b 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1931,6 +1931,7 @@ James Tocknell Bennett Todd R Lindsay Todd Eugene Toder +Heikki Toivonen Erik Tollerud Stephen Tonkin Matias Torchinsky diff --git a/Misc/NEWS.d/next/Library/2026-01-03-20-49-09.gh-issue-143409.vAsfk2.rst b/Misc/NEWS.d/next/Library/2026-01-03-20-49-09.gh-issue-143409.vAsfk2.rst new file mode 100644 index 00000000000000..301a1784d2071f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-01-03-20-49-09.gh-issue-143409.vAsfk2.rst @@ -0,0 +1 @@ +Use dict and set comprehensions when possible