File: check-assert-type-fail.test

package info (click to toggle)
mypy 1.19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,412 kB
  • sloc: python: 114,754; ansic: 13,343; cpp: 11,380; makefile: 257; sh: 28
file content (49 lines) | stat: -rw-r--r-- 1,368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[case testAssertTypeFail1]
import typing
import array as arr
class array:
    pass
def f(si: arr.array[int]):
    typing.assert_type(si, array) # E: Expression is of type "array.array[int]", not "__main__.array"
[builtins fixtures/tuple.pyi]

[case testAssertTypeFail2]
import typing
import array as arr
class array:
    class array:
        i = 1
def f(si: arr.array[int]):
    typing.assert_type(si, array.array) # E: Expression is of type "array.array[int]", not "__main__.array.array"
[builtins fixtures/tuple.pyi]

[case testAssertTypeFail3]
import typing
import array as arr
class array:
    class array:
        i = 1
def f(si: arr.array[int]):
    typing.assert_type(si, int) # E: Expression is of type "array[int]", not "int"
[builtins fixtures/tuple.pyi]

[case testAssertTypeFailCallableArgKind]
from typing import assert_type, Callable
def myfunc(arg: int) -> None: pass
assert_type(myfunc, Callable[[int], None])  # E: Expression is of type "def myfunc(arg: int) -> None", not "Callable[[int], None]"

[case testAssertTypeOverload]
from typing import assert_type, overload

class Foo:
    @overload
    def __new__(cls, x: int) -> Foo: ...
    @overload
    def __new__(cls, x: str) -> Foo: ...
    def __new__(cls, x: "int | str") -> Foo:
        return cls(0)

assert_type(Foo, type[Foo])
A = Foo
assert_type(A, type[Foo])
[builtins fixtures/tuple.pyi]