Skip to content

Support assertion style type guards in exhaustive branch analysis #11238

@KotlinIsland

Description

@KotlinIsland
def func(a: object, b: bool) -> None:
    if b:
        assert isinstance(a, int)
    else:
        assert isinstance(a, str)

    reveal_type(a)  # note: Revealed type is "builtins.object"

a should be narrowed to int | str but it is instead not narrowed at all.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions