Skip to content

Commit 014aacd

Browse files
authored
Enable ruff on Lib/test/test_typing.py (#110179)
1 parent 1dd9dee commit 014aacd

File tree

3 files changed

+53
-54
lines changed

3 files changed

+53
-54
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.0.288
3+
rev: v0.0.292
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/

Lib/test/.ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ extend-exclude = [
2626
"test_keywordonlyarg.py",
2727
"test_pkg.py",
2828
"test_subclassinit.py",
29-
"test_typing.py",
3029
"test_unittest/testmock/testpatch.py",
3130
"test_yield_from.py",
3231
"time_hashlib.py",

Lib/test/test_typing.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_cannot_subclass(self):
185185
class A(self.bottom_type):
186186
pass
187187
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
188-
class A(type(self.bottom_type)):
188+
class B(type(self.bottom_type)):
189189
pass
190190

191191
def test_cannot_instantiate(self):
@@ -282,7 +282,7 @@ class C(type(Self)):
282282
pass
283283
with self.assertRaisesRegex(TypeError,
284284
r'Cannot subclass typing\.Self'):
285-
class C(Self):
285+
class D(Self):
286286
pass
287287

288288
def test_cannot_init(self):
@@ -339,7 +339,7 @@ class C(type(LiteralString)):
339339
pass
340340
with self.assertRaisesRegex(TypeError,
341341
r'Cannot subclass typing\.LiteralString'):
342-
class C(LiteralString):
342+
class D(LiteralString):
343343
pass
344344

345345
def test_cannot_init(self):
@@ -483,7 +483,7 @@ class V(TypeVar): pass
483483
T = TypeVar("T")
484484
with self.assertRaisesRegex(TypeError,
485485
CANNOT_SUBCLASS_INSTANCE % 'TypeVar'):
486-
class V(T): pass
486+
class W(T): pass
487487

488488
def test_cannot_instantiate_vars(self):
489489
with self.assertRaises(TypeError):
@@ -1244,20 +1244,20 @@ class C(TypeVarTuple): pass
12441244
Ts = TypeVarTuple('Ts')
12451245
with self.assertRaisesRegex(TypeError,
12461246
CANNOT_SUBCLASS_INSTANCE % 'TypeVarTuple'):
1247-
class C(Ts): pass
1247+
class D(Ts): pass
12481248
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
1249-
class C(type(Unpack)): pass
1249+
class E(type(Unpack)): pass
12501250
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
1251-
class C(type(*Ts)): pass
1251+
class F(type(*Ts)): pass
12521252
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
1253-
class C(type(Unpack[Ts])): pass
1253+
class G(type(Unpack[Ts])): pass
12541254
with self.assertRaisesRegex(TypeError,
12551255
r'Cannot subclass typing\.Unpack'):
1256-
class C(Unpack): pass
1256+
class H(Unpack): pass
12571257
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[Ts\]'):
1258-
class C(*Ts): pass
1258+
class I(*Ts): pass
12591259
with self.assertRaisesRegex(TypeError, r'Cannot subclass typing.Unpack\[Ts\]'):
1260-
class C(Unpack[Ts]): pass
1260+
class J(Unpack[Ts]): pass
12611261

12621262
def test_variadic_class_args_are_correct(self):
12631263
T = TypeVar('T')
@@ -1431,12 +1431,12 @@ def test_variadic_class_with_duplicate_typevartuples_fails(self):
14311431
with self.assertRaises(TypeError):
14321432
class C(Generic[*Ts1, *Ts1]): pass
14331433
with self.assertRaises(TypeError):
1434-
class C(Generic[Unpack[Ts1], Unpack[Ts1]]): pass
1434+
class D(Generic[Unpack[Ts1], Unpack[Ts1]]): pass
14351435

14361436
with self.assertRaises(TypeError):
1437-
class C(Generic[*Ts1, *Ts2, *Ts1]): pass
1437+
class E(Generic[*Ts1, *Ts2, *Ts1]): pass
14381438
with self.assertRaises(TypeError):
1439-
class C(Generic[Unpack[Ts1], Unpack[Ts2], Unpack[Ts1]]): pass
1439+
class F(Generic[Unpack[Ts1], Unpack[Ts2], Unpack[Ts1]]): pass
14401440

14411441
def test_type_concatenation_in_variadic_class_argument_list_succeeds(self):
14421442
Ts = TypeVarTuple('Ts')
@@ -1804,11 +1804,11 @@ def test_cannot_subclass(self):
18041804
class C(Union):
18051805
pass
18061806
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
1807-
class C(type(Union)):
1807+
class D(type(Union)):
18081808
pass
18091809
with self.assertRaisesRegex(TypeError,
18101810
r'Cannot subclass typing\.Union\[int, str\]'):
1811-
class C(Union[int, str]):
1811+
class E(Union[int, str]):
18121812
pass
18131813

18141814
def test_cannot_instantiate(self):
@@ -2557,10 +2557,10 @@ class BP(Protocol): pass
25572557
class P(C, Protocol):
25582558
pass
25592559
with self.assertRaises(TypeError):
2560-
class P(Protocol, C):
2560+
class Q(Protocol, C):
25612561
pass
25622562
with self.assertRaises(TypeError):
2563-
class P(BP, C, Protocol):
2563+
class R(BP, C, Protocol):
25642564
pass
25652565

25662566
class D(BP, C): pass
@@ -2836,7 +2836,7 @@ class NotAProtocolButAnImplicitSubclass3:
28362836
meth: Callable[[], None]
28372837
meth2: Callable[[int, str], bool]
28382838
def meth(self): pass
2839-
def meth(self, x, y): return True
2839+
def meth2(self, x, y): return True
28402840

28412841
self.assertNotIsSubclass(AnnotatedButNotAProtocol, CallableMembersProto)
28422842
self.assertIsSubclass(NotAProtocolButAnImplicitSubclass, CallableMembersProto)
@@ -3658,11 +3658,11 @@ def test_protocols_bad_subscripts(self):
36583658
with self.assertRaises(TypeError):
36593659
class P(Protocol[T, T]): pass
36603660
with self.assertRaises(TypeError):
3661-
class P(Protocol[int]): pass
3661+
class Q(Protocol[int]): pass
36623662
with self.assertRaises(TypeError):
3663-
class P(Protocol[T], Protocol[S]): pass
3663+
class R(Protocol[T], Protocol[S]): pass
36643664
with self.assertRaises(TypeError):
3665-
class P(typing.Mapping[T, S], Protocol[T]): pass
3665+
class S(typing.Mapping[T, S], Protocol[T]): pass
36663666

36673667
def test_generic_protocols_repr(self):
36683668
T = TypeVar('T')
@@ -4094,12 +4094,12 @@ class NewGeneric(Generic): ...
40944094
with self.assertRaises(TypeError):
40954095
class MyGeneric(Generic[T], Generic[S]): ...
40964096
with self.assertRaises(TypeError):
4097-
class MyGeneric(List[T], Generic[S]): ...
4097+
class MyGeneric2(List[T], Generic[S]): ...
40984098
with self.assertRaises(TypeError):
40994099
Generic[()]
4100-
class C(Generic[T]): pass
4100+
class D(Generic[T]): pass
41014101
with self.assertRaises(TypeError):
4102-
C[()]
4102+
D[()]
41034103

41044104
def test_generic_subclass_checks(self):
41054105
for typ in [list[int], List[int],
@@ -4836,7 +4836,7 @@ class Test(Generic[T], Final):
48364836
class Subclass(Test):
48374837
pass
48384838
with self.assertRaises(FinalException):
4839-
class Subclass(Test[int]):
4839+
class Subclass2(Test[int]):
48404840
pass
48414841

48424842
def test_nested(self):
@@ -5074,15 +5074,15 @@ def test_cannot_subclass(self):
50745074
class C(type(ClassVar)):
50755075
pass
50765076
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
5077-
class C(type(ClassVar[int])):
5077+
class D(type(ClassVar[int])):
50785078
pass
50795079
with self.assertRaisesRegex(TypeError,
50805080
r'Cannot subclass typing\.ClassVar'):
5081-
class C(ClassVar):
5081+
class E(ClassVar):
50825082
pass
50835083
with self.assertRaisesRegex(TypeError,
50845084
r'Cannot subclass typing\.ClassVar\[int\]'):
5085-
class C(ClassVar[int]):
5085+
class F(ClassVar[int]):
50865086
pass
50875087

50885088
def test_cannot_init(self):
@@ -5124,15 +5124,15 @@ def test_cannot_subclass(self):
51245124
class C(type(Final)):
51255125
pass
51265126
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
5127-
class C(type(Final[int])):
5127+
class D(type(Final[int])):
51285128
pass
51295129
with self.assertRaisesRegex(TypeError,
51305130
r'Cannot subclass typing\.Final'):
5131-
class C(Final):
5131+
class E(Final):
51325132
pass
51335133
with self.assertRaisesRegex(TypeError,
51345134
r'Cannot subclass typing\.Final\[int\]'):
5135-
class C(Final[int]):
5135+
class F(Final[int]):
51365136
pass
51375137

51385138
def test_cannot_init(self):
@@ -7265,15 +7265,15 @@ class A:
72657265
class X(NamedTuple, A):
72667266
x: int
72677267
with self.assertRaises(TypeError):
7268-
class X(NamedTuple, tuple):
7268+
class Y(NamedTuple, tuple):
72697269
x: int
72707270
with self.assertRaises(TypeError):
7271-
class X(NamedTuple, NamedTuple):
7271+
class Z(NamedTuple, NamedTuple):
72727272
x: int
7273-
class A(NamedTuple):
7273+
class B(NamedTuple):
72747274
x: int
72757275
with self.assertRaises(TypeError):
7276-
class X(NamedTuple, A):
7276+
class C(NamedTuple, B):
72777277
y: str
72787278

72797279
def test_generic(self):
@@ -8037,15 +8037,15 @@ def test_cannot_subclass(self):
80378037
class C(type(Required)):
80388038
pass
80398039
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
8040-
class C(type(Required[int])):
8040+
class D(type(Required[int])):
80418041
pass
80428042
with self.assertRaisesRegex(TypeError,
80438043
r'Cannot subclass typing\.Required'):
8044-
class C(Required):
8044+
class E(Required):
80458045
pass
80468046
with self.assertRaisesRegex(TypeError,
80478047
r'Cannot subclass typing\.Required\[int\]'):
8048-
class C(Required[int]):
8048+
class F(Required[int]):
80498049
pass
80508050

80518051
def test_cannot_init(self):
@@ -8085,15 +8085,15 @@ def test_cannot_subclass(self):
80858085
class C(type(NotRequired)):
80868086
pass
80878087
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
8088-
class C(type(NotRequired[int])):
8088+
class D(type(NotRequired[int])):
80898089
pass
80908090
with self.assertRaisesRegex(TypeError,
80918091
r'Cannot subclass typing\.NotRequired'):
8092-
class C(NotRequired):
8092+
class E(NotRequired):
80938093
pass
80948094
with self.assertRaisesRegex(TypeError,
80958095
r'Cannot subclass typing\.NotRequired\[int\]'):
8096-
class C(NotRequired[int]):
8096+
class F(NotRequired[int]):
80978097
pass
80988098

80998099
def test_cannot_init(self):
@@ -8192,7 +8192,7 @@ class A(typing.Match):
81928192
TypeError,
81938193
r"type 're\.Pattern' is not an acceptable base type",
81948194
):
8195-
class A(typing.Pattern):
8195+
class B(typing.Pattern):
81968196
pass
81978197

81988198

@@ -8539,7 +8539,7 @@ class C(TypeAlias):
85398539
pass
85408540

85418541
with self.assertRaises(TypeError):
8542-
class C(type(TypeAlias)):
8542+
class D(type(TypeAlias)):
85438543
pass
85448544

85458545
def test_repr(self):
@@ -8929,19 +8929,19 @@ def test_cannot_subclass(self):
89298929
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpec'):
89308930
class C(ParamSpec): pass
89318931
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpecArgs'):
8932-
class C(ParamSpecArgs): pass
8932+
class D(ParamSpecArgs): pass
89338933
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpecKwargs'):
8934-
class C(ParamSpecKwargs): pass
8934+
class E(ParamSpecKwargs): pass
89358935
P = ParamSpec('P')
89368936
with self.assertRaisesRegex(TypeError,
89378937
CANNOT_SUBCLASS_INSTANCE % 'ParamSpec'):
8938-
class C(P): pass
8938+
class F(P): pass
89398939
with self.assertRaisesRegex(TypeError,
89408940
CANNOT_SUBCLASS_INSTANCE % 'ParamSpecArgs'):
8941-
class C(P.args): pass
8941+
class G(P.args): pass
89428942
with self.assertRaisesRegex(TypeError,
89438943
CANNOT_SUBCLASS_INSTANCE % 'ParamSpecKwargs'):
8944-
class C(P.kwargs): pass
8944+
class H(P.kwargs): pass
89458945

89468946

89478947
class ConcatenateTests(BaseTestCase):
@@ -9022,15 +9022,15 @@ def test_cannot_subclass(self):
90229022
class C(type(TypeGuard)):
90239023
pass
90249024
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
9025-
class C(type(TypeGuard[int])):
9025+
class D(type(TypeGuard[int])):
90269026
pass
90279027
with self.assertRaisesRegex(TypeError,
90289028
r'Cannot subclass typing\.TypeGuard'):
9029-
class C(TypeGuard):
9029+
class E(TypeGuard):
90309030
pass
90319031
with self.assertRaisesRegex(TypeError,
90329032
r'Cannot subclass typing\.TypeGuard\[int\]'):
9033-
class C(TypeGuard[int]):
9033+
class F(TypeGuard[int]):
90349034
pass
90359035

90369036
def test_cannot_init(self):

0 commit comments

Comments
 (0)