From e0a083c06940fac87f6db9c30712b53f18332fb8 Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:17:30 -0400 Subject: [PATCH 1/8] Use generator as argument to str.join() instead of list comprehension --- Lib/_pydecimal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index ff23322ed5603e..4cd9c09a59063a 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -3391,7 +3391,7 @@ def logical_and(self, other, context=None): (opa, opb) = self._fill_logical(context, self._int, other._int) # make the operation, and clean starting zeroes - result = "".join([str(int(a)&int(b)) for a,b in zip(opa,opb)]) + result = "".join(str(int(a)&int(b)) for a,b in zip(opa,opb)) return _dec_from_triple(0, result.lstrip('0') or '0', 0) def logical_invert(self, context=None): From 23bf12024adae694d3d6ef21f7a3161f1c658dd3 Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:18:15 -0400 Subject: [PATCH 2/8] Use generator as argument to str.join() instead of list comprehension --- Lib/_pydecimal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index 4cd9c09a59063a..0c5349196d6687 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -3415,7 +3415,7 @@ def logical_or(self, other, context=None): (opa, opb) = self._fill_logical(context, self._int, other._int) # make the operation, and clean starting zeroes - result = "".join([str(int(a)|int(b)) for a,b in zip(opa,opb)]) + result = "".join(str(int(a)|int(b)) for a,b in zip(opa,opb)) return _dec_from_triple(0, result.lstrip('0') or '0', 0) def logical_xor(self, other, context=None): From 29fba8da81decd247f1ce6d7efa8bc51f8483cec Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:18:58 -0400 Subject: [PATCH 3/8] Use generator as argument to str.join() instead of list comprehension --- Lib/_pydecimal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index 0c5349196d6687..ab7b3deab3131e 100644 --- a/Lib/_pydecimal.py +++ b/Lib/_pydecimal.py @@ -3432,7 +3432,7 @@ def logical_xor(self, other, context=None): (opa, opb) = self._fill_logical(context, self._int, other._int) # make the operation, and clean starting zeroes - result = "".join([str(int(a)^int(b)) for a,b in zip(opa,opb)]) + result = "".join(str(int(a)^int(b)) for a,b in zip(opa,opb)) return _dec_from_triple(0, result.lstrip('0') or '0', 0) def max_mag(self, other, context=None): From 5968060f4a562e184cc3445515f50b2035d1c8b1 Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:22:26 -0400 Subject: [PATCH 4/8] Use generator as argument to str.join() instead of list comprehension --- Lib/argparse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 8a12dea7668799..85b6c13ddb8268 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -287,9 +287,9 @@ def format_help(self): return help def _join_parts(self, part_strings): - return ''.join([part - for part in part_strings - if part and part is not SUPPRESS]) + return "".join( + part for part in part_strings if part and part is not SUPPRESS + ) def _format_usage(self, usage, actions, groups, prefix): if prefix is None: From 7930116da07b412b00e9e3630364d32f96c9dc4f Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:24:09 -0400 Subject: [PATCH 5/8] Use generator as argument to str.join() instead of list comprehension --- Lib/argparse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 85b6c13ddb8268..ca95141fe9ded3 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -621,7 +621,7 @@ def _expand_help(self, action): if hasattr(params[name], '__name__'): params[name] = params[name].__name__ if params.get('choices') is not None: - choices_str = ', '.join([str(c) for c in params['choices']]) + choices_str = ", ".join(str(c) for c in params['choices']) params['choices'] = choices_str return self._get_help_string(action) % params From 128783eb2f198d1763ceab8207570f2d4b654992 Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:26:44 -0400 Subject: [PATCH 6/8] Use generator as argument to str.join() instead of list comprehension --- Lib/argparse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index ca95141fe9ded3..71f4648f27fb6d 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -1588,9 +1588,9 @@ def _handle_conflict_error(self, action, conflicting_actions): message = ngettext('conflicting option string: %s', 'conflicting option strings: %s', len(conflicting_actions)) - conflict_string = ', '.join([option_string - for option_string, action - in conflicting_actions]) + conflict_string = ", ".join( + option_string for option_string, action in conflicting_actions + ) raise ArgumentError(action, message % conflict_string) def _handle_conflict_resolve(self, action, conflicting_actions): From 0408882856ac3b7d78ab9a93b12e224bc2c75f6c Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:28:30 -0400 Subject: [PATCH 7/8] Use generator as argument to str.join() instead of list comprehension --- Lib/argparse.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/argparse.py b/Lib/argparse.py index 71f4648f27fb6d..6ebf98beac1a14 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -2163,8 +2163,9 @@ def _match_arguments_partial(self, actions, arg_strings_pattern): result = [] for i in range(len(actions), 0, -1): actions_slice = actions[:i] - pattern = ''.join([self._get_nargs_pattern(action) - for action in actions_slice]) + pattern = "".join( + self._get_nargs_pattern(action) for action in actions_slice + ) match = _re.match(pattern, arg_strings_pattern) if match is not None: result.extend([len(string) for string in match.groups()]) From 44915e151d458298998dbff03577d4aaf8512c1d Mon Sep 17 00:00:00 2001 From: Zachary Kneupper Date: Tue, 11 May 2021 18:33:35 -0400 Subject: [PATCH 8/8] replace for loop with generator expression --- Lib/ast.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Lib/ast.py b/Lib/ast.py index 18163d6b7bd163..6422a21b07c02d 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -323,13 +323,7 @@ def _splitlines_no_ff(source): def _pad_whitespace(source): r"""Replace all chars except '\f\t' in a line with spaces.""" - result = '' - for c in source: - if c in '\f\t': - result += c - else: - result += ' ' - return result + return "".join(c if c in "\f\t" else " " for c in source) def get_source_segment(source, node, *, padded=False):