Skip to content

Commit 1f3de87

Browse files
[pre-commit] Remove pyupgrade and use ruff instead
pyupgrade is slower and introduced a bug on templated strings ("{msgid}") that does not affect ruff. Also ruff seems to handle more cases as evidenced by the new fixes.
1 parent 9c69801 commit 1f3de87

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ repos:
3333
args: ["--notice=script/copyright.txt", "--enforce-all"]
3434
exclude: tests(/\w*)*/functional/|tests/input|doc/data/messages|examples/|setup.py|tests(/\w*)*data/
3535
types: [python]
36-
- repo: https://github.com/asottile/pyupgrade
37-
rev: v3.13.0
38-
hooks:
39-
- id: pyupgrade
40-
args: [--py38-plus]
41-
exclude: *fixtures
4236
- repo: https://github.com/PyCQA/isort
4337
rev: 5.12.0
4438
hooks:

pylint/checkers/base_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def get_full_documentation(
134134
if reports:
135135
result += get_rst_title(f"{checker_title} Reports", "^")
136136
for report in reports:
137-
result += (
138-
":%s: %s\n" % report[:2] # pylint: disable=consider-using-f-string
137+
result += ":{}: {}\n".format( # pylint: disable=consider-using-f-string
138+
*report[:2]
139139
)
140140
result += "\n"
141141
result += "\n"

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,15 @@ def _check_consider_using_min_max_builtin(self, node: nodes.If) -> None:
914914
return
915915

916916
if operator in {"<", "<="}:
917-
reduced_to = "{target} = max({target}, {item})".format(
918-
target=target_assignation, item=body_value
917+
reduced_to = (
918+
f"{target_assignation} = max({target_assignation}, {body_value})"
919919
)
920920
self.add_message(
921921
"consider-using-max-builtin", node=node, args=(reduced_to,)
922922
)
923923
elif operator in {">", ">="}:
924-
reduced_to = "{target} = min({target}, {item})".format(
925-
target=target_assignation, item=body_value
924+
reduced_to = (
925+
f"{target_assignation} = min({target_assignation}, {body_value})"
926926
)
927927
self.add_message(
928928
"consider-using-min-builtin", node=node, args=(reduced_to,)

pylint/extensions/_check_docs_utils.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,10 @@ class SphinxDocstring(Docstring):
347347
[\(\[] [^\n\s]+ [\)\]] # with the contents of the container
348348
"""
349349

350-
re_multiple_simple_type = r"""
351-
(?:{container_type}|{type})
352-
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{container_type}|{type}))*
353-
""".format(
354-
type=re_type, container_type=re_simple_container_type
355-
)
350+
re_multiple_simple_type = rf"""
351+
(?:{re_simple_container_type}|{re_type})
352+
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{re_simple_container_type}|{re_type}))*
353+
"""
356354

357355
re_xref = rf"""
358356
(?::\w+:)? # optional tag
@@ -549,12 +547,10 @@ class GoogleDocstring(Docstring):
549547
[\(\[] [^\n]+ [\)\]] # with the contents of the container
550548
"""
551549

552-
re_multiple_type = r"""
553-
(?:{container_type}|{type}|{xref})
554-
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{container_type}|{type}|{xref}))*
555-
""".format(
556-
type=re_type, xref=re_xref, container_type=re_container_type
557-
)
550+
re_multiple_type = rf"""
551+
(?:{re_container_type}|{re_type}|{re_xref})
552+
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{re_container_type}|{re_type}|{re_xref}))*
553+
"""
558554

559555
_re_section_template = r"""
560556
^([ ]*) {0} \s*: \s*$ # Google parameter header

pylint/testutils/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_EXPECTED_RE = re.compile(
2424
r"\s*#\s*(?:(?P<line>[+-]?[0-9]+):)?" # pylint: disable=consider-using-f-string
2525
r"(?:(?P<op>[><=]+) *(?P<version>[0-9.]+):)?"
26-
r"\s*\[(?P<msgs>%(msg)s(?:,\s*%(msg)s)*)]" % _MESSAGE
26+
r"\s*\[(?P<msgs>{msg}(?:,\s*{msg})*)]".format(**_MESSAGE)
2727
)
2828

2929
_OPERATORS = {">": operator.gt, "<": operator.lt, ">=": operator.ge, "<=": operator.le}

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ select = [
151151
"B", # bugbear
152152
"I", # isort
153153
"RUF", # ruff
154+
"UP", # pyupgrade
154155
]
155156

156157
ignore = [
@@ -165,4 +166,5 @@ fixable = [
165166
"B", # bugbear
166167
"I", # isort
167168
"RUF", # ruff
169+
"UP", # pyupgrade
168170
]

0 commit comments

Comments
 (0)