]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 10 Oct 2023 10:35:21 +0000 (12:35 +0200)
committerGitHub <noreply@github.com>
Tue, 10 Oct 2023 10:35:21 +0000 (12:35 +0200)
gh-110558: Enable ruff's pyupgrade rules when running on Argument Clinic (GH-110603)
(cherry picked from commit fc811c8d205db9c19f42890e2c4193a0c2f87965)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
.pre-commit-config.yaml
Lib/test/test_clinic.py
Tools/clinic/.ruff.toml
Tools/clinic/clinic.py

index ffca103bb33e8602e7302e664993da52b72561c0..8ad1f33d3a60507edb352421683ac975f4f0dae0 100644 (file)
@@ -7,7 +7,7 @@ repos:
         args: [--exit-non-zero-on-fix]
         files: ^Lib/test/
       - 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]
         files: ^Tools/clinic/|Lib/test/test_clinic.py
 
index 23487958f456486b646171d9d08d622d4c288fc1..05eea78a0ce4e52dd5773853f46ead05483ac865 100644 (file)
@@ -1394,7 +1394,7 @@ class ClinicExternalTest(TestCase):
     def test_external(self):
         CLINIC_TEST = 'clinic.test.c'
         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()
 
         # Run clinic CLI and verify that it does not complain.
@@ -1402,7 +1402,7 @@ class ClinicExternalTest(TestCase):
         out = self.expect_success("-f", "-o", TESTFN, source)
         self.assertEqual(out, "")
 
-        with open(TESTFN, 'r', encoding='utf-8') as f:
+        with open(TESTFN, encoding='utf-8') as f:
             new_contents = f.read()
 
         self.assertEqual(new_contents, orig_contents)
@@ -1463,7 +1463,7 @@ class ClinicExternalTest(TestCase):
                 "/*[clinic end generated code: "
                 "output=2124c291eb067d76 input=9543a8d2da235301]*/\n"
             )
-            with open(fn, 'r', encoding='utf-8') as f:
+            with open(fn, encoding='utf-8') as f:
                 generated = f.read()
             self.assertTrue(generated.endswith(checksum))
 
index 3bc9d908ed329600d8d35e7ce492697cacb183c5..cbb3a9a8f3a8c2cfea4ffc655f9d680fe41945b0 100644 (file)
@@ -2,9 +2,24 @@ target-version = "py310"
 fix = true
 select = [
     "F",  # Enable all pyflakes rules
+    "UP",  # Enable all pyupgrade rules by default
     "RUF100",  # Ban unused `# noqa` comments
     "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 = [
     # 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
index fd394c92cad9c6cb8a401d270afc839c9269e74d..921b77bad513301f10c99dc83f3af83e712da4b1 100755 (executable)
@@ -1968,7 +1968,7 @@ extensions['py'] = PythonLanguage
 
 def write_file(filename: str, new_contents: str) -> None:
     try:
-        with open(filename, 'r', encoding="utf-8") as fp:
+        with open(filename, encoding="utf-8") as fp:
             old_contents = fp.read()
 
         if old_contents == new_contents: