-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Labels
awaiting responsewaiting for more info from the author - will eventually close if they don't respondwaiting for more info from the author - will eventually close if they don't respondtype checking / lintingissues relating to existing diagnostic rules or proposals for new diagnostic rulesissues relating to existing diagnostic rules or proposals for new diagnostic rules
Description
Description
It would be awesome if it could narrow the type based on an all isinstance check, if possible. This does a check that all the variables are of a specific type, so the inner block should know that narrowed type.
Code sample in basedpyright playground
from typing import reveal_type
def process_list(values: list[str] | list[list[str]]) -> str:
if all(isinstance(item, str) for item in values):
reveal_type(values) # Should be narrowed to list[str]
return "Should be str"
if all(isinstance(item, list) and len(item) == 2 for item in values):
reveal_type(values) # Should be narrowed to list[list[str]]
return "Should be list[str]"
return ""
Metadata
Metadata
Assignees
Labels
awaiting responsewaiting for more info from the author - will eventually close if they don't respondwaiting for more info from the author - will eventually close if they don't respondtype checking / lintingissues relating to existing diagnostic rules or proposals for new diagnostic rulesissues relating to existing diagnostic rules or proposals for new diagnostic rules