summaryrefslogtreecommitdiff
path: root/pylint/checkers
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/checkers')
-rw-r--r--pylint/checkers/base.py2
-rw-r--r--pylint/checkers/base_checker.py29
-rw-r--r--pylint/checkers/classes.py2
-rw-r--r--pylint/checkers/imports.py2
-rw-r--r--pylint/checkers/misc.py18
-rw-r--r--pylint/checkers/python3.py8
-rw-r--r--pylint/checkers/refactoring/refactoring_checker.py4
-rw-r--r--pylint/checkers/spelling.py17
-rw-r--r--pylint/checkers/strings.py2
-rw-r--r--pylint/checkers/typecheck.py4
-rw-r--r--pylint/checkers/variables.py27
11 files changed, 39 insertions, 76 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 6f6c7cbdf..aeaa85379 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -2399,7 +2399,7 @@ class ComparisonChecker(_BasicChecker):
self.add_message(
"singleton-comparison",
node=root_node,
- args=("'{}'".format(root_node.as_string()), suggestion),
+ args=(f"'{root_node.as_string()}'", suggestion),
)
def _check_literal_comparison(self, literal, node):
diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py
index ccdca6568..f7beed603 100644
--- a/pylint/checkers/base_checker.py
+++ b/pylint/checkers/base_checker.py
@@ -51,15 +51,12 @@ class BaseChecker(OptionsProviderMixIn):
def __gt__(self, other):
"""Permit to sort a list of Checker by name."""
- return "{}{}".format(self.name, self.msgs).__gt__(
- "{}{}".format(other.name, other.msgs)
- )
+ return f"{self.name}{self.msgs}".__gt__(f"{other.name}{other.msgs}")
def __repr__(self):
status = "Checker" if self.enabled else "Disabled checker"
- return "{} '{}' (responsible for '{}')".format(
- status, self.name, "', '".join(self.msgs.keys())
- )
+ msgs = "', '".join(self.msgs.keys())
+ return f"{status} '{self.name}' (responsible for '{msgs}')"
def __str__(self):
"""This might be incomplete because multiple class inheriting BaseChecker
@@ -80,15 +77,15 @@ class BaseChecker(OptionsProviderMixIn):
result += "Verbatim name of the checker is ``%s``.\n\n" % self.name
if doc:
# Provide anchor to link against
- result += get_rst_title("{} Documentation".format(checker_title), "^")
+ result += get_rst_title(f"{checker_title} Documentation", "^")
result += "%s\n\n" % cleandoc(doc)
# options might be an empty generator and not be False when casted to boolean
options = list(options)
if options:
- result += get_rst_title("{} Options".format(checker_title), "^")
+ result += get_rst_title(f"{checker_title} Options", "^")
result += "%s\n" % get_rst_section(None, options)
if msgs:
- result += get_rst_title("{} Messages".format(checker_title), "^")
+ result += get_rst_title(f"{checker_title} Messages", "^")
for msgid, msg in sorted(
msgs.items(), key=lambda kv: (_MSG_ORDER.index(kv[0][0]), kv[1])
):
@@ -96,7 +93,7 @@ class BaseChecker(OptionsProviderMixIn):
result += "%s\n" % msg.format_help(checkerref=False)
result += "\n"
if reports:
- result += get_rst_title("{} Reports".format(checker_title), "^")
+ result += get_rst_title(f"{checker_title} Reports", "^")
for report in reports:
result += ":%s: %s\n" % report[:2]
result += "\n"
@@ -124,12 +121,8 @@ class BaseChecker(OptionsProviderMixIn):
for message in self.messages:
if checker_id is not None and checker_id != message.msgid[1:3]:
error_msg = "Inconsistent checker part in message id "
- error_msg += "'{}' (expected 'x{checker_id}xx' ".format(
- message.msgid, checker_id=checker_id
- )
- error_msg += "because we already had {existing_ids}).".format(
- existing_ids=existing_ids
- )
+ error_msg += f"'{message.msgid}' (expected 'x{checker_id}xx' "
+ error_msg += f"because we already had {existing_ids})."
raise InvalidMessageError(error_msg)
checker_id = message.msgid[1:3]
existing_ids.append(message.msgid)
@@ -171,8 +164,8 @@ class BaseChecker(OptionsProviderMixIn):
for message_definition in self.messages:
if message_definition.msgid == msgid:
return message_definition
- error_msg = "MessageDefinition for '{}' does not exists. ".format(msgid)
- error_msg += "Choose from {}.".format([m.msgid for m in self.messages])
+ error_msg = f"MessageDefinition for '{msgid}' does not exists. "
+ error_msg += f"Choose from {[m.msgid for m in self.messages]}."
raise InvalidMessageError(error_msg)
def open(self):
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index 06fe30ca7..d3fb1fa60 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -402,7 +402,7 @@ def _is_attribute_property(name, klass):
attributes = klass.getattr(name)
except astroid.NotFoundError:
return False
- property_name = "{}.property".format(BUILTINS)
+ property_name = f"{BUILTINS}.property"
for attr in attributes:
if attr is astroid.Uninferable:
continue
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 37b814e30..f22cb3315 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -963,7 +963,7 @@ class ImportsChecker(BaseChecker):
return
module_names = [
- "{}.{}".format(node.modname, name[0])
+ f"{node.modname}.{name[0]}"
if isinstance(node, astroid.ImportFrom)
else name[0]
for name in node.names
diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py
index 509ed9c7b..be6fbd363 100644
--- a/pylint/checkers/misc.py
+++ b/pylint/checkers/misc.py
@@ -55,14 +55,8 @@ class ByIdManagedMessagesChecker(BaseChecker):
managed_msgs = MessagesHandlerMixIn.get_by_id_managed_msgs()
for (mod_name, msg_id, msg_symbol, lineno, is_disabled) in managed_msgs:
if mod_name == module.name:
- if is_disabled:
- txt = "Id '{ident}' is used to disable '{symbol}' message emission".format(
- ident=msg_id, symbol=msg_symbol
- )
- else:
- txt = "Id '{ident}' is used to enable '{symbol}' message emission".format(
- ident=msg_id, symbol=msg_symbol
- )
+ verb = "disable" if is_disabled else "enable"
+ txt = f"Id '{msg_id}' is used to {verb} '{msg_symbol}' message emission"
self.add_message("use-symbolic-message-instead", line=lineno, args=txt)
MessagesHandlerMixIn.clear_by_id_managed_msgs()
@@ -127,12 +121,8 @@ class EncodingChecker(BaseChecker):
pass
except LookupError:
if line.startswith("#") and "coding" in line and file_encoding in line:
- self.add_message(
- "syntax-error",
- line=lineno,
- args='Cannot decode using encoding "{}",'
- " bad encoding".format(file_encoding),
- )
+ msg = f"Cannot decode using encoding '{file_encoding}', bad encoding"
+ self.add_message("syntax-error", line=lineno, args=msg)
return None
def process_module(self, module):
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 0b9369a4a..9b46c1fe1 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -1111,7 +1111,7 @@ class Python3Checker(checkers.BaseChecker):
if not inferred:
return
- builtins_list = "{}.list".format(bases.BUILTINS)
+ builtins_list = f"{bases.BUILTINS}.list"
if isinstance(inferred, astroid.List) or inferred.qname() == builtins_list:
kwargs = node.keywords
@@ -1120,7 +1120,7 @@ class Python3Checker(checkers.BaseChecker):
if not inferred:
return
- builtins_sorted = "{}.sorted".format(bases.BUILTINS)
+ builtins_sorted = f"{bases.BUILTINS}.sorted"
if inferred.qname() == builtins_sorted:
kwargs = node.keywords
@@ -1181,7 +1181,7 @@ class Python3Checker(checkers.BaseChecker):
and node.func.attrname in DICT_METHODS
):
if not _in_iterating_context(node):
- checker = "dict-{}-not-iterating".format(node.func.attrname)
+ checker = f"dict-{node.func.attrname}-not-iterating"
self.add_message(checker, node=node)
except astroid.InferenceError:
pass
@@ -1232,7 +1232,7 @@ class Python3Checker(checkers.BaseChecker):
if _is_builtin(found_node):
if node.func.name in ("filter", "map", "range", "zip"):
if not _in_iterating_context(node):
- checker = "{}-builtin-not-iterating".format(node.func.name)
+ checker = f"{node.func.name}-builtin-not-iterating"
self.add_message(checker, node=node)
elif node.func.name == "open" and node.keywords:
kwargs = node.keywords
diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py
index 110fbd74d..81bb18213 100644
--- a/pylint/checkers/refactoring/refactoring_checker.py
+++ b/pylint/checkers/refactoring/refactoring_checker.py
@@ -622,7 +622,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
test_reduced_to = "bool(test)"
if (node.body.value, node.orelse.value) == (True, False):
- reduced_to = "'{}'".format(test_reduced_to)
+ reduced_to = f"'{test_reduced_to}'"
elif (node.body.value, node.orelse.value) == (False, True):
reduced_to = "'not test'"
else:
@@ -666,7 +666,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
@staticmethod
def _check_exception_inherit_from_stopiteration(exc):
"""Return True if the exception node in argument inherit from StopIteration"""
- stopiteration_qname = "{}.StopIteration".format(utils.EXCEPTIONS_MODULE)
+ stopiteration_qname = f"{utils.EXCEPTIONS_MODULE}.StopIteration"
return any(_class.qname() == stopiteration_qname for _class in exc.mro())
def _check_consider_using_comprehension_constructor(self, node):
diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py
index e8d00381a..4c08b855f 100644
--- a/pylint/checkers/spelling.py
+++ b/pylint/checkers/spelling.py
@@ -347,7 +347,6 @@ class SpellingChecker(BaseTokenChecker):
# Present up to N suggestions.
suggestions = self.spelling_dict.suggest(word)
del suggestions[self.config.max_spelling_suggestions :]
-
line_segment = line[word_start_at:]
match = re.search(r"(\W|^)(%s)(\W|$)" % word, line_segment)
if match:
@@ -355,23 +354,13 @@ class SpellingChecker(BaseTokenChecker):
col = match.regs[2][0]
else:
col = line_segment.index(word)
-
col += word_start_at
-
if starts_with_comment:
col += 1
indicator = (" " * col) + ("^" * len(word))
-
- self.add_message(
- msgid,
- line=line_num,
- args=(
- word,
- original_line,
- indicator,
- "'{}'".format("' or '".join(suggestions)),
- ),
- )
+ all_suggestion = "' or '".join(suggestions)
+ args = (word, original_line, indicator, "'{}'".format(all_suggestion))
+ self.add_message(msgid, line=line_num, args=args)
def process_tokens(self, tokens):
if not self.initialized:
diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py
index 3cf1d86c5..c36b06570 100644
--- a/pylint/checkers/strings.py
+++ b/pylint/checkers/strings.py
@@ -226,7 +226,7 @@ def get_access_path(key, parts):
path = []
for is_attribute, specifier in parts:
if is_attribute:
- path.append(".{}".format(specifier))
+ path.append(f".{specifier}")
else:
path.append("[{!r}]".format(specifier))
return str(key) + "".join(path)
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py
index e135f6e94..38ebfde6f 100644
--- a/pylint/checkers/typecheck.py
+++ b/pylint/checkers/typecheck.py
@@ -154,7 +154,7 @@ def _is_owner_ignored(owner, attrname, ignored_classes, ignored_modules):
if not current_module:
current_module = part
else:
- current_module += ".{}".format(part)
+ current_module += f".{part}"
if current_module in ignored_modules:
return True
@@ -246,7 +246,7 @@ def _missing_member_hint(owner, attrname, distance_threshold, max_choices):
else:
names = "one of {} or {}".format(", ".join(names[:-1]), names[-1])
- return "; maybe {}?".format(names)
+ return f"; maybe {names}?"
MSGS = {
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index e9e8a22e3..0fb296a84 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -516,24 +516,15 @@ class NamesConsumer:
self.node = node
def __repr__(self):
- msg = "\nto_consume : {:s}\n".format(
- ", ".join(
- [
- "{}->{}".format(key, val)
- for key, val in self._atomic.to_consume.items()
- ]
- )
- )
- msg += "consumed : {:s}\n".format(
- ", ".join(
- [
- "{}->{}".format(key, val)
- for key, val in self._atomic.consumed.items()
- ]
- )
- )
- msg += "scope_type : {:s}\n".format(self._atomic.scope_type)
- return msg
+ to_consumes = [f"{k}->{v}" for k, v in self._atomic.to_consume.items()]
+ consumed = [f"{k}->{v}" for k, v in self._atomic.consumed.items()]
+ to_consumes = ", ".join(to_consumes)
+ consumed = ", ".join(consumed)
+ return f"""
+to_consume : {to_consumes}
+consumed : {consumed}
+scope_type : {self._atomic.scope_type}
+"""
def __iter__(self):
return iter(self._atomic)