-
Notifications
You must be signed in to change notification settings - Fork 276
Closed
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or bothtypechecking
Description
Describe the Bug
def test(x: Union[str, tuple[int, str], tuple[int, str, str]]) -> str:
if (not isinstance(x, tuple)) or len(x) != 3:
return "nope"
reveal_type(x)
_, _, s = x
return sIn this code, at the point where the tuple unpacking occurs the parameter x is known to be a tuple of length 3, so narrowing should give it the type tuple[int, str, str].
pyrefly erroneously assigns it the type tuple[int, str] instead:
INFO sandbox.py:6:16-19: revealed type: tuple[int, str] [[reveal-type](https://pyrefly.org/en/docs/error-kinds/#reveal-type)]
ERROR sandbox.py:7:5-12: Cannot unpack tuple[int, str] (of size 2) into 3 values [[bad-unpacking](https://pyrefly.org/en/docs/error-kinds/#bad-unpacking)]
INFO sandbox.py:10:12-38: revealed type: str [[reveal-type](https://pyrefly.org/en/docs/error-kinds/#reveal-type)]
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothIssues with narrowing - root cause is usually narrowing, flow handling, or bothtypechecking