Skip to content

Commit

Permalink
[3.11] Enable ruff on Lib/test/test_typing.py (python#110179)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Oct 3, 2023
1 parent a151afe commit cf904ba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.288
rev: v0.0.292
hooks:
- id: ruff
name: Run Ruff on Lib/test/
Expand Down
1 change: 0 additions & 1 deletion Lib/test/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extend-exclude = [
"test_pkg.py",
"test_subclassinit.py",
"test_tokenize.py",
"test_typing.py",
"test_yield_from.py",
"time_hashlib.py",
]
80 changes: 40 additions & 40 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_cannot_subclass(self):
class A(self.bottom_type):
pass
with self.assertRaises(TypeError):
class A(type(self.bottom_type)):
class B(type(self.bottom_type)):
pass

def test_cannot_instantiate(self):
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_cannot_subclass(self):
class C(type(Self)):
pass
with self.assertRaises(TypeError):
class C(Self):
class D(Self):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -335,7 +335,7 @@ def test_cannot_subclass(self):
class C(type(LiteralString)):
pass
with self.assertRaises(TypeError):
class C(LiteralString):
class D(LiteralString):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -457,7 +457,7 @@ class V(TypeVar('T')):

def test_cannot_subclass_var_itself(self):
with self.assertRaises(TypeError):
class V(TypeVar):
class W(TypeVar):
pass

def test_cannot_instantiate_vars(self):
Expand Down Expand Up @@ -1185,20 +1185,20 @@ class C(TypeVarTuple): pass
def test_cannot_subclass_instance(self):
Ts = TypeVarTuple('Ts')
with self.assertRaises(TypeError):
class C(Ts): pass
class D(Ts): pass
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
class C(type(Unpack)): pass
class E(type(Unpack)): pass
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
class C(type(*Ts)): pass
class F(type(*Ts)): pass
with self.assertRaisesRegex(TypeError, CANNOT_SUBCLASS_TYPE):
class C(type(Unpack[Ts])): pass
class G(type(Unpack[Ts])): pass
with self.assertRaisesRegex(TypeError,
r'Cannot subclass typing\.Unpack'):
class C(Unpack): pass
class H(Unpack): pass
with self.assertRaisesRegex(TypeError, r'Cannot subclass \*Ts'):
class C(*Ts): pass
class I(*Ts): pass
with self.assertRaisesRegex(TypeError, r'Cannot subclass \*Ts'):
class C(Unpack[Ts]): pass
class J(Unpack[Ts]): pass

def test_variadic_class_args_are_correct(self):
T = TypeVar('T')
Expand Down Expand Up @@ -1372,12 +1372,12 @@ def test_variadic_class_with_duplicate_typevartuples_fails(self):
with self.assertRaises(TypeError):
class C(Generic[*Ts1, *Ts1]): pass
with self.assertRaises(TypeError):
class C(Generic[Unpack[Ts1], Unpack[Ts1]]): pass
class D(Generic[Unpack[Ts1], Unpack[Ts1]]): pass

with self.assertRaises(TypeError):
class C(Generic[*Ts1, *Ts2, *Ts1]): pass
class E(Generic[*Ts1, *Ts2, *Ts1]): pass
with self.assertRaises(TypeError):
class C(Generic[Unpack[Ts1], Unpack[Ts2], Unpack[Ts1]]): pass
class F(Generic[Unpack[Ts1], Unpack[Ts2], Unpack[Ts1]]): pass

def test_type_concatenation_in_variadic_class_argument_list_succeeds(self):
Ts = TypeVarTuple('Ts')
Expand Down Expand Up @@ -1744,10 +1744,10 @@ def test_cannot_subclass(self):
class C(Union):
pass
with self.assertRaises(TypeError):
class C(type(Union)):
class D(type(Union)):
pass
with self.assertRaises(TypeError):
class C(Union[int, str]):
class E(Union[int, str]):
pass

def test_cannot_instantiate(self):
Expand Down Expand Up @@ -2454,10 +2454,10 @@ class BP(Protocol): pass
class P(C, Protocol):
pass
with self.assertRaises(TypeError):
class P(Protocol, C):
class Q(Protocol, C):
pass
with self.assertRaises(TypeError):
class P(BP, C, Protocol):
class R(BP, C, Protocol):
pass

class D(BP, C): pass
Expand Down Expand Up @@ -2722,7 +2722,7 @@ class NotAProtocolButAnImplicitSubclass3:
meth: Callable[[], None]
meth2: Callable[[int, str], bool]
def meth(self): pass
def meth(self, x, y): return True
def meth2(self, x, y): return True

self.assertNotIsSubclass(AnnotatedButNotAProtocol, CallableMembersProto)
self.assertIsSubclass(NotAProtocolButAnImplicitSubclass, CallableMembersProto)
Expand Down Expand Up @@ -3208,11 +3208,11 @@ def test_protocols_bad_subscripts(self):
with self.assertRaises(TypeError):
class P(Protocol[T, T]): pass
with self.assertRaises(TypeError):
class P(Protocol[int]): pass
class Q(Protocol[int]): pass
with self.assertRaises(TypeError):
class P(Protocol[T], Protocol[S]): pass
class R(Protocol[T], Protocol[S]): pass
with self.assertRaises(TypeError):
class P(typing.Mapping[T, S], Protocol[T]): pass
class S(typing.Mapping[T, S], Protocol[T]): pass

def test_generic_protocols_repr(self):
T = TypeVar('T')
Expand Down Expand Up @@ -3553,12 +3553,12 @@ class NewGeneric(Generic): ...
with self.assertRaises(TypeError):
class MyGeneric(Generic[T], Generic[S]): ...
with self.assertRaises(TypeError):
class MyGeneric(List[T], Generic[S]): ...
class MyGeneric2(List[T], Generic[S]): ...
with self.assertRaises(TypeError):
Generic[()]
class C(Generic[T]): pass
class D(Generic[T]): pass
with self.assertRaises(TypeError):
C[()]
D[()]

def test_init(self):
T = TypeVar('T')
Expand Down Expand Up @@ -4234,7 +4234,7 @@ class Test(Generic[T], Final):
class Subclass(Test):
pass
with self.assertRaises(FinalException):
class Subclass(Test[int]):
class Subclass2(Test[int]):
pass

def test_nested(self):
Expand Down Expand Up @@ -4472,7 +4472,7 @@ def test_cannot_subclass(self):
class C(type(ClassVar)):
pass
with self.assertRaises(TypeError):
class C(type(ClassVar[int])):
class D(type(ClassVar[int])):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -4514,7 +4514,7 @@ def test_cannot_subclass(self):
class C(type(Final)):
pass
with self.assertRaises(TypeError):
class C(type(Final[int])):
class D(type(Final[int])):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -6514,15 +6514,15 @@ class A:
class X(NamedTuple, A):
x: int
with self.assertRaises(TypeError):
class X(NamedTuple, tuple):
class Y(NamedTuple, tuple):
x: int
with self.assertRaises(TypeError):
class X(NamedTuple, NamedTuple):
class Z(NamedTuple, NamedTuple):
x: int
class A(NamedTuple):
class B(NamedTuple):
x: int
with self.assertRaises(TypeError):
class X(NamedTuple, A):
class C(NamedTuple, B):
y: str

def test_generic(self):
Expand Down Expand Up @@ -7108,13 +7108,13 @@ def test_cannot_subclass(self):
class C(type(Required)):
pass
with self.assertRaises(TypeError):
class C(type(Required[int])):
class D(type(Required[int])):
pass
with self.assertRaises(TypeError):
class C(Required):
class E(Required):
pass
with self.assertRaises(TypeError):
class C(Required[int]):
class F(Required[int]):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -7154,13 +7154,13 @@ def test_cannot_subclass(self):
class C(type(NotRequired)):
pass
with self.assertRaises(TypeError):
class C(type(NotRequired[int])):
class D(type(NotRequired[int])):
pass
with self.assertRaises(TypeError):
class C(NotRequired):
class E(NotRequired):
pass
with self.assertRaises(TypeError):
class C(NotRequired[int]):
class F(NotRequired[int]):
pass

def test_cannot_init(self):
Expand Down Expand Up @@ -7622,7 +7622,7 @@ class C(TypeAlias):
pass

with self.assertRaises(TypeError):
class C(type(TypeAlias)):
class D(type(TypeAlias)):
pass

def test_repr(self):
Expand Down Expand Up @@ -8078,7 +8078,7 @@ def test_cannot_subclass(self):
class C(type(TypeGuard)):
pass
with self.assertRaises(TypeError):
class C(type(TypeGuard[int])):
class D(type(TypeGuard[int])):
pass

def test_cannot_init(self):
Expand Down

0 comments on commit cf904ba

Please sign in to comment.