Skip to content

Commit 4b221bf

Browse files
authored
[3.12] Bump Ruff to 0.6.7 (#124384) (#124391)
1 parent db48e8f commit 4b221bf

File tree

8 files changed

+11
-14
lines changed

8 files changed

+11
-14
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.3.4
3+
rev: v0.6.7
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/

Doc/tools/extensions/c_annotations.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,7 @@ def add_annotations(app: Sphinx, doctree: nodes.document) -> None:
124124
continue
125125
if not par[0].get("ids", None):
126126
continue
127-
name = par[0]["ids"][0]
128-
if name.startswith("c."):
129-
name = name[2:]
130-
127+
name = par[0]["ids"][0].removeprefix("c.")
131128
objtype = par["objtype"]
132129

133130
# Stable ABI annotation.

Lib/test/pickletester.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,9 @@ class MyIntWithNew2(MyIntWithNew):
40414041
class SlotList(MyList):
40424042
__slots__ = ["foo"]
40434043

4044-
class SimpleNewObj(int):
4044+
# Ruff "redefined while unused" false positive here due to `global` variables
4045+
# being assigned (and then restored) from within test methods earlier in the file
4046+
class SimpleNewObj(int): # noqa: F811
40454047
def __init__(self, *args, **kwargs):
40464048
# raise an error, to make sure this isn't called
40474049
raise TypeError("SimpleNewObj.__init__() didn't expect to get called")

Lib/test/test_bz2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ def testReadlinesNoNewline(self):
476476
self.assertEqual(xlines, [b'Test'])
477477

478478
def testContextProtocol(self):
479-
f = None
480479
with BZ2File(self.filename, "wb") as f:
481480
f.write(b"xxx")
482481
f = BZ2File(self.filename, "rb")

Lib/test/test_contextlib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,10 @@ class FileContextTestCase(unittest.TestCase):
434434
def testWithOpen(self):
435435
tfn = tempfile.mktemp()
436436
try:
437-
f = None
438437
with open(tfn, "w", encoding="utf-8") as f:
439438
self.assertFalse(f.closed)
440439
f.write("Booh\n")
441440
self.assertTrue(f.closed)
442-
f = None
443441
with self.assertRaises(ZeroDivisionError):
444442
with open(tfn, "r", encoding="utf-8") as f:
445443
self.assertFalse(f.closed)

Lib/test/test_io.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,9 @@ def test_large_file_ops(self):
645645

646646
def test_with_open(self):
647647
for bufsize in (0, 100):
648-
f = None
649648
with self.open(os_helper.TESTFN, "wb", bufsize) as f:
650649
f.write(b"xxx")
651650
self.assertEqual(f.closed, True)
652-
f = None
653651
try:
654652
with self.open(os_helper.TESTFN, "wb", bufsize) as f:
655653
1/0

Lib/test/test_os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3096,7 +3096,8 @@ class Win32NtTests(unittest.TestCase):
30963096
def test_getfinalpathname_handles(self):
30973097
nt = import_helper.import_module('nt')
30983098
ctypes = import_helper.import_module('ctypes')
3099-
import ctypes.wintypes
3099+
# Ruff false positive -- it thinks we're redefining `ctypes` here
3100+
import ctypes.wintypes # noqa: F811
31003101

31013102
kernel = ctypes.WinDLL('Kernel32.dll', use_last_error=True)
31023103
kernel.GetCurrentProcess.restype = ctypes.wintypes.HANDLE

Lib/test/test_with.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def __exit__(self, *args):
171171
def shouldThrow():
172172
ct = EnterThrows()
173173
self.foo = None
174-
with ct as self.foo:
174+
# Ruff complains that we're redefining `self.foo` here,
175+
# but the whole point of the test is to check that `self.foo`
176+
# is *not* redefined (because `__enter__` raises)
177+
with ct as self.foo: # ruff: noqa: F811
175178
pass
176179
self.assertRaises(RuntimeError, shouldThrow)
177180
self.assertEqual(self.foo, None)
@@ -252,7 +255,6 @@ def testInlineGeneratorBoundSyntax(self):
252255
self.assertAfterWithGeneratorInvariantsNoError(foo)
253256

254257
def testInlineGeneratorBoundToExistingVariable(self):
255-
foo = None
256258
with mock_contextmanager_generator() as foo:
257259
self.assertInWithGeneratorInvariants(foo)
258260
self.assertAfterWithGeneratorInvariantsNoError(foo)

0 commit comments

Comments
 (0)