diff --git a/Lib/_pydecimal.py b/Lib/_pydecimal.py index ff23322ed5603e..ab7b3deab3131e 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): @@ -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): @@ -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): diff --git a/Lib/argparse.py b/Lib/argparse.py index 8a12dea7668799..6ebf98beac1a14 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: @@ -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 @@ -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): @@ -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()]) 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):