Skip to content

Commit

Permalink
[pre-commit] Remove pyupgrade and use ruff instead
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Pierre-Sassoulas committed Oct 2, 2023
1 parent 9c69801 commit 1f3de87
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ repos:
args: ["--notice=script/copyright.txt", "--enforce-all"]
exclude: tests(/\w*)*/functional/|tests/input|doc/data/messages|examples/|setup.py|tests(/\w*)*data/
types: [python]
- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
hooks:
- id: pyupgrade
args: [--py38-plus]
exclude: *fixtures
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
Expand Down
4 changes: 2 additions & 2 deletions pylint/checkers/base_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def get_full_documentation(
if reports:
result += get_rst_title(f"{checker_title} Reports", "^")
for report in reports:
result += (
":%s: %s\n" % report[:2] # pylint: disable=consider-using-f-string
result += ":{}: {}\n".format( # pylint: disable=consider-using-f-string
*report[:2]
)
result += "\n"
result += "\n"
Expand Down
8 changes: 4 additions & 4 deletions pylint/checkers/refactoring/refactoring_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,15 @@ def _check_consider_using_min_max_builtin(self, node: nodes.If) -> None:
return

if operator in {"<", "<="}:
reduced_to = "{target} = max({target}, {item})".format(
target=target_assignation, item=body_value
reduced_to = (
f"{target_assignation} = max({target_assignation}, {body_value})"
)
self.add_message(
"consider-using-max-builtin", node=node, args=(reduced_to,)
)
elif operator in {">", ">="}:
reduced_to = "{target} = min({target}, {item})".format(
target=target_assignation, item=body_value
reduced_to = (
f"{target_assignation} = min({target_assignation}, {body_value})"
)
self.add_message(
"consider-using-min-builtin", node=node, args=(reduced_to,)
Expand Down
20 changes: 8 additions & 12 deletions pylint/extensions/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,10 @@ class SphinxDocstring(Docstring):
[\(\[] [^\n\s]+ [\)\]] # with the contents of the container
"""

re_multiple_simple_type = r"""
(?:{container_type}|{type})
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{container_type}|{type}))*
""".format(
type=re_type, container_type=re_simple_container_type
)
re_multiple_simple_type = rf"""
(?:{re_simple_container_type}|{re_type})
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{re_simple_container_type}|{re_type}))*
"""

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

re_multiple_type = r"""
(?:{container_type}|{type}|{xref})
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{container_type}|{type}|{xref}))*
""".format(
type=re_type, xref=re_xref, container_type=re_container_type
)
re_multiple_type = rf"""
(?:{re_container_type}|{re_type}|{re_xref})
(?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+)(?:{re_container_type}|{re_type}|{re_xref}))*
"""

_re_section_template = r"""
^([ ]*) {0} \s*: \s*$ # Google parameter header
Expand Down
2 changes: 1 addition & 1 deletion pylint/testutils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_EXPECTED_RE = re.compile(
r"\s*#\s*(?:(?P<line>[+-]?[0-9]+):)?" # pylint: disable=consider-using-f-string
r"(?:(?P<op>[><=]+) *(?P<version>[0-9.]+):)?"
r"\s*\[(?P<msgs>%(msg)s(?:,\s*%(msg)s)*)]" % _MESSAGE
r"\s*\[(?P<msgs>{msg}(?:,\s*{msg})*)]".format(**_MESSAGE)
)

_OPERATORS = {">": operator.gt, "<": operator.lt, ">=": operator.ge, "<=": operator.le}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ select = [
"B", # bugbear
"I", # isort
"RUF", # ruff
"UP", # pyupgrade
]

ignore = [
Expand All @@ -165,4 +166,5 @@ fixable = [
"B", # bugbear
"I", # isort
"RUF", # ruff
"UP", # pyupgrade
]

0 comments on commit 1f3de87

Please sign in to comment.