-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionenhancement requestNew feature or requestNew feature or request
Description
Describe the bug
pyright should support type narrowing based on tuple length to avoid the false positive in the following code snippet:
from typing import Union
MultiTuple = Union[tuple[object], tuple[object, object]]
def process_tuples(tup: MultiTuple) -> object:
if len(tup) == 1:
return tup[0]
else:
first, second = tup
return second
/home/gregory/Downloads/testcase/pytest/tuplesize.py:9:9 - error: Tuple size mismatch: expected 2 but received 1 (reportGeneralTypeIssues)
This came up in the rich codebase, and there's a corresponding mypy issue with an open PR: python/mypy#1178
Expected behavior
pyright should be able to type narrow tuples based on len()
VS Code extension or command-line
pyright 1.1.180 Linux commandline
Metadata
Metadata
Assignees
Labels
addressed in next versionIssue is fixed and will appear in next published versionIssue is fixed and will appear in next published versionenhancement requestNew feature or requestNew feature or request