Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conformance/results/mypy/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down
1 change: 1 addition & 0 deletions conformance/results/pyrefly/directives_type_checking.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
"""
2 changes: 2 additions & 0 deletions conformance/results/pyright/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -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 = """
Expand Down
1 change: 1 addition & 0 deletions conformance/results/ty/directives_type_checking.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
"""
1 change: 1 addition & 0 deletions conformance/results/zuban/directives_type_checking.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
"""
17 changes: 13 additions & 4 deletions conformance/tests/directives_type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])