diff --git a/conformance/results/mypy/directives_type_checking.toml b/conformance/results/mypy/directives_type_checking.toml index 5e485e856..38420ca99 100644 --- a/conformance/results/mypy/directives_type_checking.toml +++ b/conformance/results/mypy/directives_type_checking.toml @@ -1,5 +1,6 @@ conformant = "Pass" output = """ +directives_type_checking.py:14: error: List item 0 has incompatible type "str"; expected "int" [list-item] """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/pyrefly/directives_type_checking.toml b/conformance/results/pyrefly/directives_type_checking.toml index be211bd5b..0c9777d72 100644 --- a/conformance/results/pyrefly/directives_type_checking.toml +++ b/conformance/results/pyrefly/directives_type_checking.toml @@ -3,4 +3,5 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ +ERROR directives_type_checking.py:14:20-27: `list[str]` is not assignable to `list[int]` [bad-assignment] """ diff --git a/conformance/results/pyright/directives_type_checking.toml b/conformance/results/pyright/directives_type_checking.toml index 5e485e856..d5ae85083 100644 --- a/conformance/results/pyright/directives_type_checking.toml +++ b/conformance/results/pyright/directives_type_checking.toml @@ -1,5 +1,7 @@ conformant = "Pass" output = """ +directives_type_checking.py:14:21 - error: Type "list[str]" is not assignable to declared type "list[int]" +  "Literal['foo']" is not assignable to "int" (reportAssignmentType) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/ty/directives_type_checking.toml b/conformance/results/ty/directives_type_checking.toml index cdd4d0cd9..7c82a4a01 100644 --- a/conformance/results/ty/directives_type_checking.toml +++ b/conformance/results/ty/directives_type_checking.toml @@ -2,4 +2,5 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ +directives_type_checking.py:14:20: error[invalid-assignment] Object of type `list[int | str]` is not assignable to `list[int]` """ diff --git a/conformance/results/zuban/directives_type_checking.toml b/conformance/results/zuban/directives_type_checking.toml index cdd4d0cd9..cb24b659e 100644 --- a/conformance/results/zuban/directives_type_checking.toml +++ b/conformance/results/zuban/directives_type_checking.toml @@ -2,4 +2,5 @@ conformance_automated = "Pass" errors_diff = """ """ output = """ +directives_type_checking.py:14: error: List item 0 has incompatible type "str"; expected "int" [list-item] """ diff --git a/conformance/tests/directives_type_checking.py b/conformance/tests/directives_type_checking.py index 55a2d52df..aaaaef52c 100644 --- a/conformance/tests/directives_type_checking.py +++ b/conformance/tests/directives_type_checking.py @@ -8,11 +8,20 @@ if not TYPE_CHECKING: - a: int = "" # This should not generate an error + a: int = "" # E? Many type checkers suppress all errors in `if not TYPE_CHECKING` blocks, though this is not currently specified if TYPE_CHECKING: - b: list[int] = [1, 2, 3] + x: list[int] = ["foo"] # E: In a `if TYPE_CHECKING` block, type checkers should report all errors as normal else: - b: list[str] = ["a", "b", "c"] + x: list[str] = [42] # E? Many type checkers suppress all errors in `else` blocks of `if TYPE_CHECKING`, though this is not currently specified -assert_type(b, list[int]) + +def foo(x: list[int], y: list[str]) -> None: + z: list[int] | list[str] + + if TYPE_CHECKING: + z = x + else: + z = y + + assert_type(z, list[int])