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)
count = statistic.count
count += sum(stat.count for stat in stats_for_error_code)
self._write('{count:<5} {error_code} {message}'.format(
count=count,
error_code=error_code,
message=statistic.message,
))
self._write(f'{count:<5} {error_code} {statistic.message}')
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

View file

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

View file

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

View file

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

View file

@ -295,7 +295,7 @@ class Option:
parts.append(arg)
for k, v in self.filtered_option_kwargs.items():
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:
"""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 exceptions.ExecutionError(
"Expected `per-file-ignores` to be a mapping from file exclude "
"patterns to ignore codes.\n\n"
"Configured `per-file-ignores` setting:\n\n{}".format(
_indent(value)
)
f"Expected `per-file-ignores` to be a mapping from file exclude "
f"patterns to ignore codes.\n\n"
f"Configured `per-file-ignores` setting:\n\n{_indent(value)}"
)
for token in _tokenize_files_to_codes_mapping(value):