Skip to content

Type inference with 'not isinstance' checks #476

Closed
@JukkaL

Description

@JukkaL

Code like this currently fails but should be okay:

def f(x: Union[int, str]) -> None:
    if not isinstance(x, int):
        return
    x + 2   # x must be int here so this is okay, but mypy complains

Note that this works currently (without the not operator):

def f(x: Union[int, str]) -> None:
    if isinstance(x, str):
        return
    x + 2  # this is considered valid, as it should be

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions