Skip to content

Commit 4dac406

Browse files
authored
[3.12] Enable ruff on Lib/test/test_typing.py (#110179) (#110288)
Enable ruff on `Lib/test/test_typing.py` (#110179)
1 parent bd56c51 commit 4dac406

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
@@ -34,7 +34,6 @@ extend-exclude = [
3434
"test_pkg.py",
3535
"test_subclassinit.py",
3636
"test_tokenize.py",
37-
"test_typing.py",
3837
"test_yield_from.py",
3938
"time_hashlib.py",
4039
# Pending https://github.com/python/cpython/pull/109139

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)
@@ -3646,11 +3646,11 @@ def test_protocols_bad_subscripts(self):
36463646
with self.assertRaises(TypeError):
36473647
class P(Protocol[T, T]): pass
36483648
with self.assertRaises(TypeError):
3649-
class P(Protocol[int]): pass
3649+
class Q(Protocol[int]): pass
36503650
with self.assertRaises(TypeError):
3651-
class P(Protocol[T], Protocol[S]): pass
3651+
class R(Protocol[T], Protocol[S]): pass
36523652
with self.assertRaises(TypeError):
3653-
class P(typing.Mapping[T, S], Protocol[T]): pass
3653+
class S(typing.Mapping[T, S], Protocol[T]): pass
36543654

36553655
def test_generic_protocols_repr(self):
36563656
T = TypeVar('T')
@@ -4029,12 +4029,12 @@ class NewGeneric(Generic): ...
40294029
with self.assertRaises(TypeError):
40304030
class MyGeneric(Generic[T], Generic[S]): ...
40314031
with self.assertRaises(TypeError):
4032-
class MyGeneric(List[T], Generic[S]): ...
4032+
class MyGeneric2(List[T], Generic[S]): ...
40334033
with self.assertRaises(TypeError):
40344034
Generic[()]
4035-
class C(Generic[T]): pass
4035+
class D(Generic[T]): pass
40364036
with self.assertRaises(TypeError):
4037-
C[()]
4037+
D[()]
40384038

40394039
def test_init(self):
40404040
T = TypeVar('T')
@@ -4755,7 +4755,7 @@ class Test(Generic[T], Final):
47554755
class Subclass(Test):
47564756
pass
47574757
with self.assertRaises(FinalException):
4758-
class Subclass(Test[int]):
4758+
class Subclass2(Test[int]):
47594759
pass
47604760

47614761
def test_nested(self):
@@ -4993,15 +4993,15 @@ def test_cannot_subclass(self):
49934993
class C(type(ClassVar)):
49944994
pass
49954995
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
4996-
class C(type(ClassVar[int])):
4996+
class D(type(ClassVar[int])):
49974997
pass
49984998
with self.assertRaisesRegex(TypeError,
49994999
r'Cannot subclass typing\.ClassVar'):
5000-
class C(ClassVar):
5000+
class E(ClassVar):
50015001
pass
50025002
with self.assertRaisesRegex(TypeError,
50035003
r'Cannot subclass typing\.ClassVar\[int\]'):
5004-
class C(ClassVar[int]):
5004+
class F(ClassVar[int]):
50055005
pass
50065006

50075007
def test_cannot_init(self):
@@ -5043,15 +5043,15 @@ def test_cannot_subclass(self):
50435043
class C(type(Final)):
50445044
pass
50455045
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
5046-
class C(type(Final[int])):
5046+
class D(type(Final[int])):
50475047
pass
50485048
with self.assertRaisesRegex(TypeError,
50495049
r'Cannot subclass typing\.Final'):
5050-
class C(Final):
5050+
class E(Final):
50515051
pass
50525052
with self.assertRaisesRegex(TypeError,
50535053
r'Cannot subclass typing\.Final\[int\]'):
5054-
class C(Final[int]):
5054+
class F(Final[int]):
50555055
pass
50565056

50575057
def test_cannot_init(self):
@@ -7180,15 +7180,15 @@ class A:
71807180
class X(NamedTuple, A):
71817181
x: int
71827182
with self.assertRaises(TypeError):
7183-
class X(NamedTuple, tuple):
7183+
class Y(NamedTuple, tuple):
71847184
x: int
71857185
with self.assertRaises(TypeError):
7186-
class X(NamedTuple, NamedTuple):
7186+
class Z(NamedTuple, NamedTuple):
71877187
x: int
7188-
class A(NamedTuple):
7188+
class B(NamedTuple):
71897189
x: int
71907190
with self.assertRaises(TypeError):
7191-
class X(NamedTuple, A):
7191+
class C(NamedTuple, B):
71927192
y: str
71937193

71947194
def test_generic(self):
@@ -7869,15 +7869,15 @@ def test_cannot_subclass(self):
78697869
class C(type(Required)):
78707870
pass
78717871
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
7872-
class C(type(Required[int])):
7872+
class D(type(Required[int])):
78737873
pass
78747874
with self.assertRaisesRegex(TypeError,
78757875
r'Cannot subclass typing\.Required'):
7876-
class C(Required):
7876+
class E(Required):
78777877
pass
78787878
with self.assertRaisesRegex(TypeError,
78797879
r'Cannot subclass typing\.Required\[int\]'):
7880-
class C(Required[int]):
7880+
class F(Required[int]):
78817881
pass
78827882

78837883
def test_cannot_init(self):
@@ -7917,15 +7917,15 @@ def test_cannot_subclass(self):
79177917
class C(type(NotRequired)):
79187918
pass
79197919
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
7920-
class C(type(NotRequired[int])):
7920+
class D(type(NotRequired[int])):
79217921
pass
79227922
with self.assertRaisesRegex(TypeError,
79237923
r'Cannot subclass typing\.NotRequired'):
7924-
class C(NotRequired):
7924+
class E(NotRequired):
79257925
pass
79267926
with self.assertRaisesRegex(TypeError,
79277927
r'Cannot subclass typing\.NotRequired\[int\]'):
7928-
class C(NotRequired[int]):
7928+
class F(NotRequired[int]):
79297929
pass
79307930

79317931
def test_cannot_init(self):
@@ -8045,7 +8045,7 @@ class A(typing.Match):
80458045
TypeError,
80468046
r"type 're\.Pattern' is not an acceptable base type",
80478047
):
8048-
class A(typing.Pattern):
8048+
class B(typing.Pattern):
80498049
pass
80508050

80518051

@@ -8393,7 +8393,7 @@ class C(TypeAlias):
83938393
pass
83948394

83958395
with self.assertRaises(TypeError):
8396-
class C(type(TypeAlias)):
8396+
class D(type(TypeAlias)):
83978397
pass
83988398

83998399
def test_repr(self):
@@ -8783,19 +8783,19 @@ def test_cannot_subclass(self):
87838783
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpec'):
87848784
class C(ParamSpec): pass
87858785
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpecArgs'):
8786-
class C(ParamSpecArgs): pass
8786+
class D(ParamSpecArgs): pass
87878787
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'ParamSpecKwargs'):
8788-
class C(ParamSpecKwargs): pass
8788+
class E(ParamSpecKwargs): pass
87898789
P = ParamSpec('P')
87908790
with self.assertRaisesRegex(TypeError,
87918791
CANNOT_SUBCLASS_INSTANCE % 'ParamSpec'):
8792-
class C(P): pass
8792+
class F(P): pass
87938793
with self.assertRaisesRegex(TypeError,
87948794
CANNOT_SUBCLASS_INSTANCE % 'ParamSpecArgs'):
8795-
class C(P.args): pass
8795+
class G(P.args): pass
87968796
with self.assertRaisesRegex(TypeError,
87978797
CANNOT_SUBCLASS_INSTANCE % 'ParamSpecKwargs'):
8798-
class C(P.kwargs): pass
8798+
class H(P.kwargs): pass
87998799

88008800

88018801
class ConcatenateTests(BaseTestCase):
@@ -8876,15 +8876,15 @@ def test_cannot_subclass(self):
88768876
class C(type(TypeGuard)):
88778877
pass
88788878
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
8879-
class C(type(TypeGuard[int])):
8879+
class D(type(TypeGuard[int])):
88808880
pass
88818881
with self.assertRaisesRegex(TypeError,
88828882
r'Cannot subclass typing\.TypeGuard'):
8883-
class C(TypeGuard):
8883+
class E(TypeGuard):
88848884
pass
88858885
with self.assertRaisesRegex(TypeError,
88868886
r'Cannot subclass typing\.TypeGuard\[int\]'):
8887-
class C(TypeGuard[int]):
8887+
class F(TypeGuard[int]):
88888888
pass
88898889

88908890
def test_cannot_init(self):

0 commit comments

Comments
 (0)