Skip to content
Merged
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
16 changes: 8 additions & 8 deletions conformance/tests/tuples_type_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ def func4(
def func5(val: tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]):
if len(val) == 1:
# Type can be narrowed to tuple[int].
assert_type(val, tuple[int]) # tuple[int]
assert_type(val, tuple[int]) # E?: tuple[int]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the test not very useful (without manual review) since type checkers will now pass no matter what type they infer for val. One solution could be to use two types and asserts that exactly one of them errors, by using an error group and asserting for both the narrowed and non-narrowed type. However, we don't currently check in that case that there is exactly one error. I can send a PR doing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me.


if len(val) == 2:
# Type can be narrowed to tuple[str, str] | tuple[int, int].
assert_type(val, tuple[str, str] | tuple[int, int])
assert_type(val, tuple[str, str] | tuple[int, int]) # E?

if len(val) == 3:
# Type can be narrowed to tuple[int, str, int].
assert_type(val, tuple[int, str, int])
assert_type(val, tuple[int, str, int]) # E?


# > This property may also be used to safely narrow tuple types within a match
Expand All @@ -92,15 +92,15 @@ def func6(val: tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int])
match val:
case (x,):
# Type can be narrowed to tuple[int].
assert_type(val, tuple[int]) # tuple[int]
assert_type(val, tuple[int]) # E?: tuple[int]

case (x, y):
# Type can be narrowed to tuple[str, str] | tuple[int, int].
assert_type(val, tuple[str, str] | tuple[int, int])
assert_type(val, tuple[str, str] | tuple[int, int]) # E?

case (x, y, z):
# Type can be narrowed to tuple[int, str, int].
assert_type(val, tuple[int, str, int])
assert_type(val, tuple[int, str, int]) # E?


# > Type checkers may safely use this equivalency rule (tuple expansion)
Expand All @@ -112,9 +112,9 @@ def func6(val: tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int])
def func7(subj: tuple[int | str, int | str]):
match subj:
case x, str():
assert_type(subj, tuple[int | str, str])
assert_type(subj, tuple[int | str, str]) # E?
case y:
assert_type(subj, tuple[int | str, int])
assert_type(subj, tuple[int | str, int]) # E?


# > The tuple class derives from Sequence[T_co] where ``T_co`` is a covariant
Expand Down