Skip to content

Commit c4c4351

Browse files
committedMar 31, 2021
audit .format(...) calls
1 parent cb36e20 commit c4c4351

File tree

6 files changed

+10
-26
lines changed

6 files changed

+10
-26
lines changed
 

‎docs/source/internal/writing-code.rst

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

‎src/flake8/checker.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ def _make_processor(self) -> Optional[processor.FileProcessor]:
380380
# NOTE(sigmavirus24): Historically, pep8 has always reported this
381381
# as an E902. We probably *want* a better error code for this
382382
# going forward.
383-
message = "{}: {}".format(type(e).__name__, e)
384-
self.report("E902", 0, 0, message)
383+
self.report("E902", 0, 0, f"{type(e).__name__}: {e}")
385384
return None
386385

387386
def report(
@@ -473,10 +472,7 @@ def run_ast_checks(self) -> None:
473472
except (ValueError, SyntaxError, TypeError) as e:
474473
row, column = self._extract_syntax_information(e)
475474
self.report(
476-
"E999",
477-
row,
478-
column,
479-
"{}: {}".format(type(e).__name__, e.args[0]),
475+
"E999", row, column, f"{type(e).__name__}: {e.args[0]}"
480476
)
481477
return
482478

‎src/flake8/exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class InvalidSyntax(Flake8Exception):
3939
def __init__(self, exception: Exception) -> None:
4040
"""Initialize our InvalidSyntax exception."""
4141
self.original_exception = exception
42-
self.error_message = "{}: {}".format(
43-
exception.__class__.__name__, exception.args[0]
42+
self.error_message = (
43+
f"{type(exception).__name__}: {exception.args[0]}"
4444
)
4545
self.error_code = "E902"
4646
self.line_number = 1

‎src/flake8/formatting/base.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ def show_statistics(self, statistics: "Statistics") -> None:
121121
statistic = next(stats_for_error_code)
122122
count = statistic.count
123123
count += sum(stat.count for stat in stats_for_error_code)
124-
self._write(
125-
"{count:<5} {error_code} {message}".format(
126-
count=count,
127-
error_code=error_code,
128-
message=statistic.message,
129-
)
130-
)
124+
self._write(f"{count:<5} {error_code} {statistic.message}")
131125

132126
def show_benchmarks(self, benchmarks: List[Tuple[str, float]]) -> None:
133127
"""Format and print the benchmarks."""

‎src/flake8/options/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def __repr__(self) -> str: # noqa: D105
295295
parts.append(arg)
296296
for k, v in self.filtered_option_kwargs.items():
297297
parts.append(f"{k}={v!r}")
298-
return "Option({})".format(", ".join(parts))
298+
return f"Option({', '.join(parts)})"
299299

300300
def normalize(self, value: Any, *normalize_args: str) -> Any:
301301
"""Normalize the value based on the option configuration."""

‎src/flake8/utils.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ def _indent(s: str) -> str:
126126
return " " + s.strip().replace("\n", "\n ")
127127

128128
return exceptions.ExecutionError(
129-
"Expected `per-file-ignores` to be a mapping from file exclude "
130-
"patterns to ignore codes.\n\n"
131-
"Configured `per-file-ignores` setting:\n\n{}".format(
132-
_indent(value)
133-
)
129+
f"Expected `per-file-ignores` to be a mapping from file exclude "
130+
f"patterns to ignore codes.\n\n"
131+
f"Configured `per-file-ignores` setting:\n\n{_indent(value)}"
134132
)
135133

136134
for token in _tokenize_files_to_codes_mapping(value):

0 commit comments

Comments
 (0)
Please sign in to comment.