mirror of https://github.com/python/cpython
gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic (#110603)
This commit is contained in:
parent
757cc35b6b
commit
fc811c8d20
|
@ -7,7 +7,7 @@ repos:
|
||||||
args: [--exit-non-zero-on-fix]
|
args: [--exit-non-zero-on-fix]
|
||||||
files: ^Lib/test/
|
files: ^Lib/test/
|
||||||
- id: ruff
|
- id: ruff
|
||||||
name: Run Ruff on Tools/clinic/
|
name: Run Ruff on Argument Clinic
|
||||||
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
|
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
|
||||||
files: ^Tools/clinic/|Lib/test/test_clinic.py
|
files: ^Tools/clinic/|Lib/test/test_clinic.py
|
||||||
|
|
||||||
|
|
|
@ -2398,7 +2398,7 @@ class ClinicExternalTest(TestCase):
|
||||||
def test_external(self):
|
def test_external(self):
|
||||||
CLINIC_TEST = 'clinic.test.c'
|
CLINIC_TEST = 'clinic.test.c'
|
||||||
source = support.findfile(CLINIC_TEST)
|
source = support.findfile(CLINIC_TEST)
|
||||||
with open(source, 'r', encoding='utf-8') as f:
|
with open(source, encoding='utf-8') as f:
|
||||||
orig_contents = f.read()
|
orig_contents = f.read()
|
||||||
|
|
||||||
# Run clinic CLI and verify that it does not complain.
|
# Run clinic CLI and verify that it does not complain.
|
||||||
|
@ -2406,7 +2406,7 @@ class ClinicExternalTest(TestCase):
|
||||||
out = self.expect_success("-f", "-o", TESTFN, source)
|
out = self.expect_success("-f", "-o", TESTFN, source)
|
||||||
self.assertEqual(out, "")
|
self.assertEqual(out, "")
|
||||||
|
|
||||||
with open(TESTFN, 'r', encoding='utf-8') as f:
|
with open(TESTFN, encoding='utf-8') as f:
|
||||||
new_contents = f.read()
|
new_contents = f.read()
|
||||||
|
|
||||||
self.assertEqual(new_contents, orig_contents)
|
self.assertEqual(new_contents, orig_contents)
|
||||||
|
@ -2466,7 +2466,7 @@ class ClinicExternalTest(TestCase):
|
||||||
"/*[clinic end generated code: "
|
"/*[clinic end generated code: "
|
||||||
"output=c16447c01510dfb3 input=9543a8d2da235301]*/\n"
|
"output=c16447c01510dfb3 input=9543a8d2da235301]*/\n"
|
||||||
)
|
)
|
||||||
with open(fn, 'r', encoding='utf-8') as f:
|
with open(fn, encoding='utf-8') as f:
|
||||||
generated = f.read()
|
generated = f.read()
|
||||||
self.assertTrue(generated.endswith(checksum),
|
self.assertTrue(generated.endswith(checksum),
|
||||||
(generated, checksum))
|
(generated, checksum))
|
||||||
|
|
|
@ -2,9 +2,24 @@ target-version = "py310"
|
||||||
fix = true
|
fix = true
|
||||||
select = [
|
select = [
|
||||||
"F", # Enable all pyflakes rules
|
"F", # Enable all pyflakes rules
|
||||||
|
"UP", # Enable all pyupgrade rules by default
|
||||||
"RUF100", # Ban unused `# noqa` comments
|
"RUF100", # Ban unused `# noqa` comments
|
||||||
"PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes)
|
"PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes)
|
||||||
]
|
]
|
||||||
|
ignore = [
|
||||||
|
# Unnecessary parentheses to functools.lru_cache: just leads to unnecessary churn.
|
||||||
|
# https://github.com/python/cpython/pull/104684#discussion_r1199653347.
|
||||||
|
"UP011",
|
||||||
|
# Use format specifiers instead of %-style formatting.
|
||||||
|
# Doesn't always make code more readable.
|
||||||
|
"UP031",
|
||||||
|
# Use f-strings instead of format specifiers.
|
||||||
|
# Doesn't always make code more readable.
|
||||||
|
"UP032",
|
||||||
|
# Use PEP-604 unions rather than tuples for isinstance() checks.
|
||||||
|
# Makes code slower and more verbose. https://github.com/astral-sh/ruff/issues/7871.
|
||||||
|
"UP038",
|
||||||
|
]
|
||||||
unfixable = [
|
unfixable = [
|
||||||
# The autofixes sometimes do the wrong things for these;
|
# The autofixes sometimes do the wrong things for these;
|
||||||
# it's better to have to manually look at the code and see how it needs fixing
|
# it's better to have to manually look at the code and see how it needs fixing
|
||||||
|
|
|
@ -2423,7 +2423,7 @@ extensions['py'] = PythonLanguage
|
||||||
|
|
||||||
def write_file(filename: str, new_contents: str) -> None:
|
def write_file(filename: str, new_contents: str) -> None:
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r', encoding="utf-8") as fp:
|
with open(filename, encoding="utf-8") as fp:
|
||||||
old_contents = fp.read()
|
old_contents = fp.read()
|
||||||
|
|
||||||
if old_contents == new_contents:
|
if old_contents == new_contents:
|
||||||
|
|
Loading…
Reference in New Issue