Skip to content

Commit 1d5dc5f

Browse files
picnixzAA-Turner
andauthored
gh-132396: Resolve 'redefinition of unused name' errors in Lib/test/ (#132397)
Co-authored-by: Adam Turner <[email protected]>
1 parent 4c3d187 commit 1d5dc5f

File tree

9 files changed

+22
-26
lines changed

9 files changed

+22
-26
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.9.1
3+
rev: v0.11.4
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/

Lib/test/.ruff.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@ extend-exclude = [
44
"test_clinic.py",
55
# Excluded (these aren't actually executed, they're just "data files")
66
"tokenizedata/*.py",
7-
# Failed to lint
7+
# Non UTF-8 files
88
"encoded_modules/module_iso_8859_1.py",
99
"encoded_modules/module_koi8_r.py",
10-
# TODO Fix: F811 Redefinition of unused name
11-
"test_buffer.py",
12-
"test_dataclasses/__init__.py",
13-
"test_descr.py",
14-
"test_enum.py",
15-
"test_functools.py",
10+
# New grammar constructions may not yet be recognized by Ruff,
11+
# and tests re-use the same names as only the grammar is being checked.
1612
"test_grammar.py",
17-
"test_import/__init__.py",
18-
"test_pkg.py",
19-
"test_yield_from.py",
2013
]
2114

2215
[lint]

Lib/test/test_dataclasses/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,12 @@ class Point:
771771

772772
# Because this is a ClassVar, it can be mutable.
773773
@dataclass
774-
class C:
774+
class UsesMutableClassVar:
775775
z: ClassVar[typ] = typ()
776776

777777
# Because this is a ClassVar, it can be mutable.
778778
@dataclass
779-
class C:
779+
class UsesMutableClassVarWithSubType:
780780
x: ClassVar[typ] = Subclass()
781781

782782
def test_deliberately_mutable_defaults(self):
@@ -4864,21 +4864,21 @@ class A:
48644864

48654865
# But this usage is okay, since it's not using KW_ONLY.
48664866
@dataclass
4867-
class A:
4867+
class NoDuplicateKwOnlyAnnotation:
48684868
a: int
48694869
_: KW_ONLY
48704870
b: int
48714871
c: int = field(kw_only=True)
48724872

48734873
# And if inheriting, it's okay.
48744874
@dataclass
4875-
class A:
4875+
class BaseUsesKwOnly:
48764876
a: int
48774877
_: KW_ONLY
48784878
b: int
48794879
c: int
48804880
@dataclass
4881-
class B(A):
4881+
class SubclassUsesKwOnly(BaseUsesKwOnly):
48824882
_: KW_ONLY
48834883
d: int
48844884

Lib/test/test_descr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,9 @@ class C(object):
11921192
pass
11931193
else:
11941194
self.fail("[''] slots not caught")
1195-
class C(object):
1195+
1196+
class WithValidIdentifiers(object):
11961197
__slots__ = ["a", "a_b", "_a", "A0123456789Z"]
1197-
# XXX(nnorwitz): was there supposed to be something tested
1198-
# from the class above?
11991198

12001199
# Test a single string is not expanded as a sequence.
12011200
class C(object):

Lib/test/test_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,15 +1352,15 @@ class Color(Enum):
13521352
red = 1
13531353
green = 2
13541354
blue = 3
1355-
def red(self):
1355+
def red(self): # noqa: F811
13561356
return 'red'
13571357
#
13581358
with self.assertRaises(TypeError):
13591359
class Color(Enum):
13601360
@enum.property
13611361
def red(self):
13621362
return 'redder'
1363-
red = 1
1363+
red = 1 # noqa: F811
13641364
green = 2
13651365
blue = 3
13661366

Lib/test/test_import/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def test_double_const(self):
444444
# (SF bug 422177).
445445
from test.test_import.data import double_const
446446
unload('test.test_import.data.double_const')
447-
from test.test_import.data import double_const
447+
from test.test_import.data import double_const # noqa: F811
448448

449449
def test_import(self):
450450
def test_with_extension(ext):
@@ -573,7 +573,7 @@ def test_issue31286(self):
573573

574574
# import in a 'for' loop resulted in segmentation fault
575575
for i in range(2):
576-
import test.support.script_helper as x
576+
import test.support.script_helper as x # noqa: F811
577577

578578
def test_failing_reload(self):
579579
# A failing reload should leave the module object in sys.modules.

Lib/test/test_pkg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def test_5(self):
190190
]
191191
self.mkhier(hier)
192192

193-
import t5
194193
s = """
195194
from t5 import *
196195
self.assertEqual(dir(), ['foo', 'self', 'string', 't5'])

Lib/test/test_with.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def shouldThrow():
174174
# Ruff complains that we're redefining `self.foo` here,
175175
# but the whole point of the test is to check that `self.foo`
176176
# is *not* redefined (because `__enter__` raises)
177-
with ct as self.foo: # ruff: noqa: F811
177+
with ct as self.foo: # noqa: F811
178178
pass
179179
self.assertRaises(RuntimeError, shouldThrow)
180180
self.assertEqual(self.foo, None)

Lib/test/test_yield_from.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ def two():
896896
yield 2
897897
g1 = one()
898898
self.assertEqual(list(g1), [0, 1, 2, 3])
899+
899900
# Check with send
900901
g1 = one()
901902
res = [next(g1)]
@@ -905,6 +906,8 @@ def two():
905906
except StopIteration:
906907
pass
907908
self.assertEqual(res, [0, 1, 2, 3])
909+
910+
def test_delegating_generators_claim_to_be_running_with_throw(self):
908911
# Check with throw
909912
class MyErr(Exception):
910913
pass
@@ -941,8 +944,10 @@ def two():
941944
except:
942945
self.assertEqual(res, [0, 1, 2, 3])
943946
raise
947+
948+
def test_delegating_generators_claim_to_be_running_with_close(self):
944949
# Check with close
945-
class MyIt(object):
950+
class MyIt:
946951
def __iter__(self):
947952
return self
948953
def __next__(self):

0 commit comments

Comments
 (0)