audit .format(...) calls

This commit is contained in:
Anthony Sottile 2021-03-29 19:54:47 -07:00
parent cb36e206a5
commit c4c4351699
6 changed files with 10 additions and 26 deletions

View file

@ -175,11 +175,7 @@ across multiple lines, insert a new-line after the opening parenthesis, e.g.,
statistic = next(stats_for_error_code) statistic = next(stats_for_error_code)
count = statistic.count count = statistic.count
count += sum(stat.count for stat in stats_for_error_code) count += sum(stat.count for stat in stats_for_error_code)
self._write('{count:<5} {error_code} {message}'.format( self._write(f'{count:<5} {error_code} {statistic.message}')
count=count,
error_code=error_code,
message=statistic.message,
))
In the first example, we put a few of the parameters all on one line, and then In the first example, we put a few of the parameters all on one line, and then
added the last two on their own. In the second example, each parameter has its added the last two on their own. In the second example, each parameter has its

View file

@ -380,8 +380,7 @@ class FileChecker:
# NOTE(sigmavirus24): Historically, pep8 has always reported this # NOTE(sigmavirus24): Historically, pep8 has always reported this
# as an E902. We probably *want* a better error code for this # as an E902. We probably *want* a better error code for this
# going forward. # going forward.
message = "{}: {}".format(type(e).__name__, e) self.report("E902", 0, 0, f"{type(e).__name__}: {e}")
self.report("E902", 0, 0, message)
return None return None
def report( def report(
@ -473,10 +472,7 @@ class FileChecker:
except (ValueError, SyntaxError, TypeError) as e: except (ValueError, SyntaxError, TypeError) as e:
row, column = self._extract_syntax_information(e) row, column = self._extract_syntax_information(e)
self.report( self.report(
"E999", "E999", row, column, f"{type(e).__name__}: {e.args[0]}"
row,
column,
"{}: {}".format(type(e).__name__, e.args[0]),
) )
return return

View file

@ -39,8 +39,8 @@ class InvalidSyntax(Flake8Exception):
def __init__(self, exception: Exception) -> None: def __init__(self, exception: Exception) -> None:
"""Initialize our InvalidSyntax exception.""" """Initialize our InvalidSyntax exception."""
self.original_exception = exception self.original_exception = exception
self.error_message = "{}: {}".format( self.error_message = (
exception.__class__.__name__, exception.args[0] f"{type(exception).__name__}: {exception.args[0]}"
) )
self.error_code = "E902" self.error_code = "E902"
self.line_number = 1 self.line_number = 1

View file

@ -121,13 +121,7 @@ class BaseFormatter:
statistic = next(stats_for_error_code) statistic = next(stats_for_error_code)
count = statistic.count count = statistic.count
count += sum(stat.count for stat in stats_for_error_code) count += sum(stat.count for stat in stats_for_error_code)
self._write( self._write(f"{count:<5} {error_code} {statistic.message}")
"{count:<5} {error_code} {message}".format(
count=count,
error_code=error_code,
message=statistic.message,
)
)
def show_benchmarks(self, benchmarks: List[Tuple[str, float]]) -> None: def show_benchmarks(self, benchmarks: List[Tuple[str, float]]) -> None:
"""Format and print the benchmarks.""" """Format and print the benchmarks."""

View file

@ -295,7 +295,7 @@ class Option:
parts.append(arg) parts.append(arg)
for k, v in self.filtered_option_kwargs.items(): for k, v in self.filtered_option_kwargs.items():
parts.append(f"{k}={v!r}") parts.append(f"{k}={v!r}")
return "Option({})".format(", ".join(parts)) return f"Option({', '.join(parts)})"
def normalize(self, value: Any, *normalize_args: str) -> Any: def normalize(self, value: Any, *normalize_args: str) -> Any:
"""Normalize the value based on the option configuration.""" """Normalize the value based on the option configuration."""

View file

@ -126,11 +126,9 @@ def parse_files_to_codes_mapping( # noqa: C901
return " " + s.strip().replace("\n", "\n ") return " " + s.strip().replace("\n", "\n ")
return exceptions.ExecutionError( return exceptions.ExecutionError(
"Expected `per-file-ignores` to be a mapping from file exclude " f"Expected `per-file-ignores` to be a mapping from file exclude "
"patterns to ignore codes.\n\n" f"patterns to ignore codes.\n\n"
"Configured `per-file-ignores` setting:\n\n{}".format( f"Configured `per-file-ignores` setting:\n\n{_indent(value)}"
_indent(value)
)
) )
for token in _tokenize_files_to_codes_mapping(value): for token in _tokenize_files_to_codes_mapping(value):