Debian Codegraph @

test-data/unit/check-assert-type-fail.test

raw
1 [case testAssertTypeFail1]
2 import typing
3 import array as arr
4 class array:
5 pass
6 def f(si: arr.array[int]):
7 typing.assert_type(si, array) # E: Expression is of type "array.array[int]", not "__main__.array"
8 [builtins fixtures/tuple.pyi]
9
10 [case testAssertTypeFail2]
11 import typing
12 import array as arr
13 class array:
14 class array:
15 i = 1
16 def f(si: arr.array[int]):
17 typing.assert_type(si, array.array) # E: Expression is of type "array.array[int]", not "__main__.array.array"
18 [builtins fixtures/tuple.pyi]
19
20 [case testAssertTypeFail3]
21 import typing
22 import array as arr
23 class array:
24 class array:
25 i = 1
26 def f(si: arr.array[int]):
27 typing.assert_type(si, int) # E: Expression is of type "array[int]", not "int"
28 [builtins fixtures/tuple.pyi]
29
30 [case testAssertTypeFailCallableArgKind]
31 from typing import assert_type, Callable
32 def myfunc(arg: int) -> None: pass
33 assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "def myfunc(arg: int) -> None", not "Callable[[int], None]"
34
35 [case testAssertTypeOverload]
36 from typing import assert_type, overload
37
38 class Foo:
39 @overload
40 def __new__(cls, x: int) -> Foo: ...
41 @overload
42 def __new__(cls, x: str) -> Foo: ...
43 def __new__(cls, x: "int | str") -> Foo:
44 return cls(0)
45
46 assert_type(Foo, type[Foo])
47 A = Foo
48 assert_type(A, type[Foo])
49 [builtins fixtures/tuple.pyi]