-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
documentationfeaturepriority-1-normaltopic-finalPEP 591PEP 591topic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
This is a feature request.
Example unit test:
[case testIsNarrowAny]
from typing import Any, Type, Union
def narrow_any_to_str_then_reassign_to_int() -> None:
v = 1 # type: Union[Type[Any], int]
if v is Any:
reveal_type(v) # N: Revealed type is 'Type[Any]'
v = 2
reveal_type(v) # N: Revealed type is 'int'
[builtins fixtures/isinstance.pyi]For a project I'm working on, it would be help readability if I could write code like the above. However, mypy does not perform type narrowing in this case, so that results in a lot of type warnings.
Note: This is different from type(x) is C. In this case, x is the type instance itself, so no subclasses are involved.
Metadata
Metadata
Assignees
Labels
documentationfeaturepriority-1-normaltopic-finalPEP 591PEP 591topic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder