]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Bump Ruff to 0.6.7 (#124384) (#124391)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Mon, 23 Sep 2024 23:09:27 +0000 (16:09 -0700)
committerGitHub <noreply@github.com>
Mon, 23 Sep 2024 23:09:27 +0000 (23:09 +0000)
.pre-commit-config.yaml
Doc/tools/extensions/c_annotations.py
Lib/test/pickletester.py
Lib/test/test_bz2.py
Lib/test/test_contextlib.py
Lib/test/test_io.py
Lib/test/test_os.py
Lib/test/test_with.py

index c64ca3186775f2dd571b686def0beaa7ea184373..0bc0ebf43fed437fdfc35ec59a068290a1659cb5 100644 (file)
@@ -1,6 +1,6 @@
 repos:
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: v0.3.4
+    rev: v0.6.7
     hooks:
       - id: ruff
         name: Run Ruff (lint) on Doc/
index a65cf71e4affe3f36b55f1a79500dc9316697332..50065d34a2c27a3152367f34625ca94344258783 100644 (file)
@@ -124,10 +124,7 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
             continue
         if not par[0].get("ids", None):
             continue
-        name = par[0]["ids"][0]
-        if name.startswith("c."):
-            name = name[2:]
-
+        name = par[0]["ids"][0].removeprefix("c.")
         objtype = par["objtype"]
 
         # Stable ABI annotation.
index 9dd4d87cd00a02aab9bc7b76a24fa9e2bfa2ea3e..b0968afcf683f3a7d10b088cfcf4c7148808529d 100644 (file)
@@ -4041,7 +4041,9 @@ class MyIntWithNew2(MyIntWithNew):
 class SlotList(MyList):
     __slots__ = ["foo"]
 
-class SimpleNewObj(int):
+# Ruff "redefined while unused" false positive here due to `global` variables
+# being assigned (and then restored) from within test methods earlier in the file
+class SimpleNewObj(int):  # noqa: F811
     def __init__(self, *args, **kwargs):
         # raise an error, to make sure this isn't called
         raise TypeError("SimpleNewObj.__init__() didn't expect to get called")
index 772f0eacce28f529fbc1b9d8f230050f894027a1..cb730a1a46e25a10267231a7a177c8ee041798f5 100644 (file)
@@ -476,7 +476,6 @@ class BZ2FileTest(BaseTest):
         self.assertEqual(xlines, [b'Test'])
 
     def testContextProtocol(self):
-        f = None
         with BZ2File(self.filename, "wb") as f:
             f.write(b"xxx")
         f = BZ2File(self.filename, "rb")
index a50a4ed7ee4912032beb651a93156fc591566610..b03ce497faac3a0ac3a53a83c1a0809137fdbadb 100644 (file)
@@ -434,12 +434,10 @@ class FileContextTestCase(unittest.TestCase):
     def testWithOpen(self):
         tfn = tempfile.mktemp()
         try:
-            f = None
             with open(tfn, "w", encoding="utf-8") as f:
                 self.assertFalse(f.closed)
                 f.write("Booh\n")
             self.assertTrue(f.closed)
-            f = None
             with self.assertRaises(ZeroDivisionError):
                 with open(tfn, "r", encoding="utf-8") as f:
                     self.assertFalse(f.closed)
index 8b68653779e7338b77fa666601d0ead289bfc401..adabf6d6ed7aca880994795bb0c6c079ed277136 100644 (file)
@@ -645,11 +645,9 @@ class IOTest(unittest.TestCase):
 
     def test_with_open(self):
         for bufsize in (0, 100):
-            f = None
             with self.open(os_helper.TESTFN, "wb", bufsize) as f:
                 f.write(b"xxx")
             self.assertEqual(f.closed, True)
-            f = None
             try:
                 with self.open(os_helper.TESTFN, "wb", bufsize) as f:
                     1/0
index 7a04e5ad500153c4c0fff7b38966b364e7e41a9a..8277ec9b608e846b269b3b4a466192f4e2f9149a 100644 (file)
@@ -3096,7 +3096,8 @@ class Win32NtTests(unittest.TestCase):
     def test_getfinalpathname_handles(self):
         nt = import_helper.import_module('nt')
         ctypes = import_helper.import_module('ctypes')
-        import ctypes.wintypes
+        # Ruff false positive -- it thinks we're redefining `ctypes` here
+        import ctypes.wintypes  # noqa: F811
 
         kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True)
         kernel.GetCurrentProcess.restype = ctypes.wintypes.HANDLE
index e8c4ddf979e2eea1c937ef352ed20b3b862faba7..839cdec68d573e9b7259f32ba8a174ec8d55e386 100644 (file)
@@ -171,7 +171,10 @@ class FailureTestCase(unittest.TestCase):
         def shouldThrow():
             ct = EnterThrows()
             self.foo = None
-            with ct as self.foo:
+            # Ruff complains that we're redefining `self.foo` here,
+            # but the whole point of the test is to check that `self.foo`
+            # is *not* redefined (because `__enter__` raises)
+            with ct as self.foo:  # ruff: noqa: F811
                 pass
         self.assertRaises(RuntimeError, shouldThrow)
         self.assertEqual(self.foo, None)
@@ -252,7 +255,6 @@ class NonexceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
         self.assertAfterWithGeneratorInvariantsNoError(foo)
 
     def testInlineGeneratorBoundToExistingVariable(self):
-        foo = None
         with mock_contextmanager_generator() as foo:
             self.assertInWithGeneratorInvariants(foo)
         self.assertAfterWithGeneratorInvariantsNoError(foo)