Skip to content

Commit fc811c8

Browse files
authored
gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic (#110603)
1 parent 757cc35 commit fc811c8

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,15 +2398,15 @@ def expect_failure(self, *args):
23982398
def test_external(self):
23992399
CLINIC_TEST = 'clinic.test.c'
24002400
source = support.findfile(CLINIC_TEST)
2401-
with open(source, 'r', encoding='utf-8') as f:
2401+
with open(source, encoding='utf-8') as f:
24022402
orig_contents = f.read()
24032403

24042404
# Run clinic CLI and verify that it does not complain.
24052405
self.addCleanup(unlink, TESTFN)
24062406
out = self.expect_success("-f", "-o", TESTFN, source)
24072407
self.assertEqual(out, "")
24082408

2409-
with open(TESTFN, 'r', encoding='utf-8') as f:
2409+
with open(TESTFN, encoding='utf-8') as f:
24102410
new_contents = f.read()
24112411

24122412
self.assertEqual(new_contents, orig_contents)
@@ -2466,7 +2466,7 @@ def test_cli_force(self):
24662466
"/*[clinic end generated code: "
24672467
"output=c16447c01510dfb3 input=9543a8d2da235301]*/\n"
24682468
)
2469-
with open(fn, 'r', encoding='utf-8') as f:
2469+
with open(fn, encoding='utf-8') as f:
24702470
generated = f.read()
24712471
self.assertTrue(generated.endswith(checksum),
24722472
(generated, checksum))

Tools/clinic/.ruff.toml

Lines changed: 15 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ def dump(self) -> str:
24232423

24242424
def write_file(filename: str, new_contents: str) -> None:
24252425
try:
2426-
with open(filename, 'r', encoding="utf-8") as fp:
2426+
with open(filename, encoding="utf-8") as fp:
24272427
old_contents = fp.read()
24282428

24292429
if old_contents == new_contents:

0 commit comments

Comments
 (0)