diff --git a/ChangeLog b/ChangeLog index d39a0248de..26c82cf1ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,10 @@ Release date: TBA .. Put new features here and also in 'doc/whatsnew/2.11.rst' +* Added ``consider-using-f-string``: Emitted when .format() or '%' is being used to format a string. + + Closes #3592 + What's New in Pylint 2.10.3? ============================ @@ -193,7 +197,6 @@ Release date: 2021-08-20 * Allow ``true`` and ``false`` values in ``pylintrc`` for better compatibility with ``toml`` config. - * Class methods' signatures are ignored the same way as functions' with similarities "ignore-signatures" option enabled Closes #4653 diff --git a/doc/exts/pylint_extensions.py b/doc/exts/pylint_extensions.py index 02e9be5bc2..4dc6f184f6 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/doc/whatsnew/2.11.rst b/doc/whatsnew/2.11.rst index fc370ecd4b..e9c05b9091 100644 --- a/doc/whatsnew/2.11.rst +++ b/doc/whatsnew/2.11.rst @@ -12,6 +12,10 @@ Summary -- Release highlights New checkers ============ +* Added ``consider-using-f-string``: Emitted when .format() or '%' is being used to format a string. + + Closes #3592 + Extensions ========== diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index 4bc586a1c4..ffc9402232 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 4422ab3360..6aba62d79d 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", @@ -404,12 +404,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") @@ -1703,8 +1703,7 @@ def _create_naming_options(): "type": "choice", "choices": list(NAMING_STYLES.keys()), "metavar": "