summaryrefslogtreecommitdiff
path: root/pylint/reporters
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-08-30 07:57:05 +0200
committerGitHub <noreply@github.com>2021-08-30 07:57:05 +0200
commit66ffcbc4c59e41327be1a2b5ef65727bf0314aa9 (patch)
tree5b1f37a0ffadc2888f851337b36f75717ebf4c72 /pylint/reporters
parent1a19421058dcc04446f8b91a825ed1078959d87a (diff)
downloadpylint-git-66ffcbc4c59e41327be1a2b5ef65727bf0314aa9.tar.gz
Add ``Consider-using-f-string`` checker (#4796)
* Add ``consider-using-f-string`` checker This adds a checker for normal strings which are formatted with ``.format()`` or '%'. The message is a convention to nudge users towards using f-strings. This closes #3592 * 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. * Apply suggestions from code review Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/reporters')
-rw-r--r--pylint/reporters/base_reporter.py2
-rw-r--r--pylint/reporters/reports_handler_mix_in.py2
-rw-r--r--pylint/reporters/text.py9
-rw-r--r--pylint/reporters/ureports/nodes.py4
-rw-r--r--pylint/reporters/ureports/text_writer.py2
5 files changed, 9 insertions, 10 deletions
diff --git a/pylint/reporters/base_reporter.py b/pylint/reporters/base_reporter.py
index 067a32c77..fda99f4ef 100644
--- a/pylint/reporters/base_reporter.py
+++ b/pylint/reporters/base_reporter.py
@@ -42,7 +42,7 @@ class BaseReporter:
"""display results encapsulated in the layout tree"""
self.section = 0
if hasattr(layout, "report_id"):
- layout.children[0].children[0].data += " (%s)" % layout.report_id
+ layout.children[0].children[0].data += f" ({layout.report_id})"
self._display(layout)
def _display(self, layout):
diff --git a/pylint/reporters/reports_handler_mix_in.py b/pylint/reporters/reports_handler_mix_in.py
index f42824559..914556ef4 100644
--- a/pylint/reporters/reports_handler_mix_in.py
+++ b/pylint/reporters/reports_handler_mix_in.py
@@ -51,7 +51,7 @@ class ReportsHandlerMixIn:
def make_reports(self, stats, old_stats):
"""render registered reports"""
- sect = Section("Report", "%s statements analysed." % (self.stats["statement"]))
+ sect = Section("Report", f"{self.stats['statement']} statements analysed.")
for checker in self.report_order():
for reportid, r_title, r_cb in self._reports[checker]:
if not self.report_is_enabled(reportid):
diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py
index 865b3c84d..6d9a05f78 100644
--- a/pylint/reporters/text.py
+++ b/pylint/reporters/text.py
@@ -147,7 +147,7 @@ class TextReporter(BaseReporter):
"""manage message of different type and in the context of path"""
if msg.module not in self._modules:
if msg.module:
- self.writeln("************* Module %s" % msg.module)
+ self.writeln(f"************* Module {msg.module}")
self._modules.add(msg.module)
else:
self.writeln("************* ")
@@ -171,8 +171,7 @@ class ParseableTextReporter(TextReporter):
def __init__(self, output=None):
warnings.warn(
- "%s output format is deprecated. This is equivalent "
- "to --msg-template=%s" % (self.name, self.line_format),
+ f"{self.name} output format is deprecated. This is equivalent to --msg-template={self.line_format}",
DeprecationWarning,
)
TextReporter.__init__(self, output)
@@ -227,10 +226,10 @@ class ColorizedTextReporter(TextReporter):
color, style = self._get_decoration("S")
if msg.module:
modsep = colorize_ansi(
- "************* Module %s" % msg.module, color, style
+ f"************* Module {msg.module}", color, style
)
else:
- modsep = colorize_ansi("************* %s" % msg.module, color, style)
+ modsep = colorize_ansi(f"************* {msg.module}", color, style)
self.writeln(modsep)
self._modules.add(msg.module)
color, style = self._get_decoration(msg.C)
diff --git a/pylint/reporters/ureports/nodes.py b/pylint/reporters/ureports/nodes.py
index 76d75959c..d359093b8 100644
--- a/pylint/reporters/ureports/nodes.py
+++ b/pylint/reporters/ureports/nodes.py
@@ -50,11 +50,11 @@ class VNode:
return self.__class__.__name__.lower()
def accept(self, visitor, *args, **kwargs):
- func = getattr(visitor, "visit_%s" % self._get_visit_name())
+ func = getattr(visitor, f"visit_{self._get_visit_name()}")
return func(self, *args, **kwargs)
def leave(self, visitor, *args, **kwargs):
- func = getattr(visitor, "leave_%s" % self._get_visit_name())
+ func = getattr(visitor, f"leave_{self._get_visit_name()}")
return func(self, *args, **kwargs)
diff --git a/pylint/reporters/ureports/text_writer.py b/pylint/reporters/ureports/text_writer.py
index 42b03f0ae..a48d73aac 100644
--- a/pylint/reporters/ureports/text_writer.py
+++ b/pylint/reporters/ureports/text_writer.py
@@ -94,4 +94,4 @@ class TextWriter(BaseWriter):
def visit_text(self, layout):
"""add some text"""
- self.write("%s" % layout.data)
+ self.write(f"{layout.data}")