Skip to content

Commit 55d6076

Browse files
[3.12] gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic (GH-110603) (#110609)
gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic (GH-110603) (cherry picked from commit fc811c8) Co-authored-by: Alex Waygood <[email protected]>
1 parent 190660a commit 55d6076

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
args: [--exit-non-zero-on-fix]
88
files: ^Lib/test/
99
- id: ruff
10-
name: Run Ruff on Tools/clinic/
10+
name: Run Ruff on Argument Clinic
1111
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
1212
files: ^Tools/clinic/|Lib/test/test_clinic.py
1313

Lib/test/test_clinic.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1394,15 +1394,15 @@ def expect_failure(self, *args):
13941394
def test_external(self):
13951395
CLINIC_TEST = 'clinic.test.c'
13961396
source = support.findfile(CLINIC_TEST)
1397-
with open(source, 'r', encoding='utf-8') as f:
1397+
with open(source, encoding='utf-8') as f:
13981398
orig_contents = f.read()
13991399

14001400
# Run clinic CLI and verify that it does not complain.
14011401
self.addCleanup(unlink, TESTFN)
14021402
out = self.expect_success("-f", "-o", TESTFN, source)
14031403
self.assertEqual(out, "")
14041404

1405-
with open(TESTFN, 'r', encoding='utf-8') as f:
1405+
with open(TESTFN, encoding='utf-8') as f:
14061406
new_contents = f.read()
14071407

14081408
self.assertEqual(new_contents, orig_contents)
@@ -1463,7 +1463,7 @@ def test_cli_force(self):
14631463
"/*[clinic end generated code: "
14641464
"output=2124c291eb067d76 input=9543a8d2da235301]*/\n"
14651465
)
1466-
with open(fn, 'r', encoding='utf-8') as f:
1466+
with open(fn, encoding='utf-8') as f:
14671467
generated = f.read()
14681468
self.assertTrue(generated.endswith(checksum))
14691469

Tools/clinic/.ruff.toml

+15
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@ target-version = "py310"
22
fix = true
33
select = [
44
"F", # Enable all pyflakes rules
5+
"UP", # Enable all pyupgrade rules by default
56
"RUF100", # Ban unused `# noqa` comments
67
"PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes)
78
]
9+
ignore = [
10+
# Unnecessary parentheses to functools.lru_cache: just leads to unnecessary churn.
11+
# https://github.com/python/cpython/pull/104684#discussion_r1199653347.
12+
"UP011",
13+
# Use format specifiers instead of %-style formatting.
14+
# Doesn't always make code more readable.
15+
"UP031",
16+
# Use f-strings instead of format specifiers.
17+
# Doesn't always make code more readable.
18+
"UP032",
19+
# Use PEP-604 unions rather than tuples for isinstance() checks.
20+
# Makes code slower and more verbose. https://github.com/astral-sh/ruff/issues/7871.
21+
"UP038",
22+
]
823
unfixable = [
924
# The autofixes sometimes do the wrong things for these;
1025
# it's better to have to manually look at the code and see how it needs fixing

Tools/clinic/clinic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ def dump(self):
19681968

19691969
def write_file(filename: str, new_contents: str) -> None:
19701970
try:
1971-
with open(filename, 'r', encoding="utf-8") as fp:
1971+
with open(filename, encoding="utf-8") as fp:
19721972
old_contents = fp.read()
19731973

19741974
if old_contents == new_contents:

0 commit comments

Comments
 (0)