From 8bd4d79d7a6369322f28c1047658538d14be4b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 20 Aug 2021 13:02:01 +0200 Subject: [PATCH] Update pylint code to use f-strings After adding `consider-using-f-strings` the codebase showed numerous cases of formatting which could be f-strings. This commit changes most of these to become f-strings, or adds ignores. --- doc/exts/pylint_extensions.py | 2 +- pylint/checkers/__init__.py | 4 +- pylint/checkers/base.py | 18 +-- pylint/checkers/base_checker.py | 20 +-- pylint/checkers/classes.py | 3 +- pylint/checkers/exceptions.py | 17 +-- pylint/checkers/imports.py | 22 ++- pylint/checkers/misc.py | 2 +- pylint/checkers/raw_metrics.py | 4 +- pylint/checkers/refactoring/not_checker.py | 6 +- .../refactoring/refactoring_checker.py | 6 +- pylint/checkers/similar.py | 8 +- pylint/checkers/spelling.py | 6 +- pylint/checkers/strings.py | 8 +- pylint/checkers/typecheck.py | 2 +- pylint/checkers/variables.py | 11 +- pylint/config/__init__.py | 2 +- pylint/config/man_help_formatter.py | 7 +- pylint/config/option.py | 5 +- pylint/config/option_manager_mixin.py | 2 +- pylint/epylint.py | 4 +- pylint/extensions/_check_docs_utils.py | 144 +++++++----------- pylint/extensions/broad_try_clause.py | 4 +- pylint/extensions/mccabe.py | 8 +- pylint/extensions/overlapping_exceptions.py | 6 +- pylint/graph.py | 24 +-- pylint/lint/pylinter.py | 13 +- pylint/lint/report_functions.py | 2 +- pylint/lint/run.py | 5 +- pylint/lint/utils.py | 4 +- pylint/message/message_definition.py | 12 +- pylint/message/message_handler_mix_in.py | 14 +- pylint/pyreverse/diadefslib.py | 4 +- pylint/pyreverse/diagrams.py | 4 +- pylint/pyreverse/inspector.py | 4 +- pylint/pyreverse/utils.py | 8 +- pylint/pyreverse/vcg_printer.py | 2 +- pylint/reporters/base_reporter.py | 2 +- pylint/reporters/reports_handler_mix_in.py | 2 +- pylint/reporters/text.py | 9 +- pylint/reporters/ureports/nodes.py | 4 +- pylint/reporters/ureports/text_writer.py | 2 +- pylint/testutils/constants.py | 6 +- pylint/testutils/lint_module_test.py | 16 +- pylint/testutils/reporter_for_tests.py | 2 +- pylint/utils/utils.py | 18 +-- script/bump_changelog.py | 10 +- tests/benchmark/test_baseline_benchmarks.py | 40 ++--- tests/checkers/unittest_python3.py | 4 +- tests/checkers/unittest_similar.py | 68 ++++----- tests/functional/a/arguments.py | 2 +- tests/functional/d/docstrings.py | 2 +- .../d/duplicate_string_formatting_argument.py | 2 +- .../l/logging_format_interpolation.py | 2 +- tests/functional/l/logging_not_lazy.py | 3 +- .../l/logging_not_lazy_with_logger.py | 1 + .../l/logging_not_lazy_with_logger.txt | 6 +- .../functional/m/misplaced_format_function.py | 2 +- tests/functional/n/new_style_class_py_30.py | 5 +- tests/functional/n/new_style_class_py_30.txt | 6 +- .../r/raise/raising_format_tuple.py | 6 +- .../r/renamed_import_logging_not_lazy.py | 2 +- tests/functional/s/slots_checks.py | 2 +- .../s/string/string_formatting_error.py | 2 +- .../string_formatting_failed_inference.py | 2 +- ...string_formatting_failed_inference_py35.py | 2 +- .../s/string/string_formatting_py3.py | 2 +- .../t/too/too_many_return_statements.py | 2 +- .../u/undefined/undefined_loop_variable.py | 2 +- tests/functional/u/unused/unused_argument.py | 2 +- .../u/use/used_before_assignement.py | 2 +- .../u/use/used_before_assignment_issue853.py | 2 +- tests/input/func_w0401_package/thing2.py | 2 +- .../profile/test_profile_against_externals.py | 7 +- tests/pyreverse/test_utils.py | 2 +- tests/test_check_parallel.py | 5 +- tests/test_epylint.py | 2 + tests/test_func.py | 5 +- tests/test_self.py | 12 +- 79 files changed, 310 insertions(+), 384 deletions(-) diff --git a/doc/exts/pylint_extensions.py b/doc/exts/pylint_extensions.py index 02e9be5bc23..4dc6f184f62 100755 --- a/doc/exts/pylint_extensions.py +++ b/doc/exts/pylint_extensions.py @@ -37,7 +37,7 @@ def builder_inited(app): if name[0] == "_" or name in DEPRECATED_MODULES: continue if ext == ".py": - modules.append("pylint.extensions.%s" % name) + modules.append(f"pylint.extensions.{name}") elif ext == ".rst": doc_files["pylint.extensions." + name] = os.path.join(ext_path, filename) modules.sort() diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index 4bc586a1c4c..ffc9402232f 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -65,8 +65,8 @@ def table_lines_from_stats(stats, old_stats, columns): diff_str = diff_string(old, new) else: old, diff_str = "NC", "NC" - new = "%.3f" % new if isinstance(new, float) else str(new) - old = "%.3f" % old if isinstance(old, float) else str(old) + new = f"{new:.3f}" if isinstance(new, float) else str(new) + old = f"{old:.3f}" if isinstance(old, float) else str(old) lines += (m_type.replace("_", " "), new, old, diff_str) return lines diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py index 352e20ebe46..ae4ca15d289 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -193,7 +193,7 @@ class AnyStyle(NamingStyle): ["set()", "{}", "[]"], ), **{ - x: "%s()" % x + x: f"{x}()" for x in ( "collections.deque", "collections.ChainMap", @@ -407,12 +407,12 @@ def report_by_type_stats(sect, stats, old_stats): try: documented = total - stats["undocumented_" + node_type] percent = (documented * 100.0) / total - nice_stats[node_type]["percent_documented"] = "%.2f" % percent + nice_stats[node_type]["percent_documented"] = f"{percent:.2f}" except KeyError: nice_stats[node_type]["percent_documented"] = "NC" try: percent = (stats["badname_" + node_type] * 100.0) / total - nice_stats[node_type]["percent_badname"] = "%.2f" % percent + nice_stats[node_type]["percent_badname"] = f"{percent:.2f}" except KeyError: nice_stats[node_type]["percent_badname"] = "NC" lines = ("type", "number", "old number", "difference", "%documented", "%badname") @@ -1706,8 +1706,7 @@ def _create_naming_options(): "type": "choice", "choices": list(NAMING_STYLES.keys()), "metavar": "