Skip to content

Commit

Permalink
[cleanup] Remove '!r' on formatting of string and str call in fstring
Browse files Browse the repository at this point in the history
str's repr is the string, and you don't need a string call in a fstring.

Follow-up to pylint-dev#7153 (comment)
  • Loading branch information
Pierre-Sassoulas committed Jul 13, 2022
1 parent 322f7c0 commit 07ca266
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def _get_imported_module(self, importnode, modname):
return None
self.add_message("relative-beyond-top-level", node=importnode)
except astroid.AstroidSyntaxError as exc:
message = f"Cannot import {modname!r} due to syntax error {str(exc.error)!r}" # pylint: disable=no-member; false positive
message = f"Cannot import {modname!r} due to syntax error {exc.error!r}" # pylint: disable=no-member; false positive
self.add_message("syntax-error", line=importnode.lineno, args=message)

except astroid.AstroidBuildingError:
Expand Down
2 changes: 1 addition & 1 deletion pylint/config/arguments_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def get_option_def(self, opt: str) -> OptionDict: # pragma: no cover
if option[0] == opt:
return option[1]
raise optparse.OptionError(
f"no such option {opt} in section {self.name!r}", opt # type: ignore[arg-type]
f"no such option {opt} in section {self.name}", opt # type: ignore[arg-type]
)

def options_by_section(
Expand Down
4 changes: 1 addition & 3 deletions pylint/config/options_provider_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def get_option_def(self, opt):
for option in self.options:
if option[0] == opt:
return option[1]
raise optparse.OptionError(
f"no such option {opt} in section {self.name!r}", opt
)
raise optparse.OptionError(f"no such option {opt} in section {self.name}", opt)

def options_by_section(self):
"""Return an iterator on options grouped by section.
Expand Down
4 changes: 2 additions & 2 deletions pylint/message/message_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def __init__(
@staticmethod
def check_msgid(msgid: str) -> None:
if len(msgid) != 5:
raise InvalidMessageError(f"Invalid message id {msgid!r}")
raise InvalidMessageError(f"Invalid message id {msgid}")
if msgid[0] not in MSG_TYPES:
raise InvalidMessageError(f"Bad message type {msgid[0]} in {msgid!r}")
raise InvalidMessageError(f"Bad message type {msgid[0]} in {msgid}")

def __eq__(self, other: Any) -> bool:
return (
Expand Down
2 changes: 1 addition & 1 deletion pylint/pyreverse/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_children(self) -> list[nodes.Module]:
return self.modules

def __repr__(self) -> str:
return f"<Project {self.name!r} at {id(self)} ({len(self.modules)} modules)>"
return f"<Project {self.name} at {id(self)} ({len(self.modules)} modules)>"


class Linker(IdGeneratorMixIn, utils.LocalsVisitor):
Expand Down
4 changes: 2 additions & 2 deletions tests/checkers/base/unittest_name_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def _test_is_correct(
naming_style: type[base.NamingStyle], name: str, name_type: str
) -> None:
rgx = naming_style.get_regex(name_type)
fail = f"{name!r} does not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
fail = f"{name} does not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
assert rgx.match(name), fail

@staticmethod
def _test_is_incorrect(
naming_style: type[base.NamingStyle], name: str, name_type: str
) -> None:
rgx = naming_style.get_regex(name_type)
fail = f"{name!r} not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
fail = f"{name} not match pattern {rgx!r} (style: {naming_style}, type: {name_type})"
assert not rgx.match(name), fail

def test_snake_case(self) -> None:
Expand Down

0 comments on commit 07ca266

Please sign in to comment.