diff --git a/docs/source/internal/writing-code.rst b/docs/source/internal/writing-code.rst index d8c63fe..daf1d57 100644 --- a/docs/source/internal/writing-code.rst +++ b/docs/source/internal/writing-code.rst @@ -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 diff --git a/src/flake8/checker.py b/src/flake8/checker.py index ceff965..421d461 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -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 diff --git a/src/flake8/exceptions.py b/src/flake8/exceptions.py index caa4677..a8d2f6e 100644 --- a/src/flake8/exceptions.py +++ b/src/flake8/exceptions.py @@ -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 diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py index 81897b2..e362e65 100644 --- a/src/flake8/formatting/base.py +++ b/src/flake8/formatting/base.py @@ -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.""" diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index 5019499..28cee4d 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -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.""" diff --git a/src/flake8/utils.py b/src/flake8/utils.py index 530801d..ee81de7 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -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):