Skip to content

FR: Type narrowing for x is C #7642

Description

@jbwdevries

This is a feature request.

Example unit test:

[casetestIsNarrowAny]
fromtypingimportAny, Type, Uniondefnarrow_any_to_str_then_reassign_to_int() ->None:
v=1# type: Union[Type[Any], int]ifvisAny:
reveal_type(v) # N: Revealed type is 'Type[Any]'v=2reveal_type(v) # N: Revealed type is 'int'
[builtinsfixtures/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

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions