Skip to content

Type inference with 'not isinstance' checks #476

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions