Skip to content

Type inference with 'not isinstance' checks #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JukkaL opened this issue Oct 12, 2014 · 1 comment
Closed

Type inference with 'not isinstance' checks #476

JukkaL opened this issue Oct 12, 2014 · 1 comment
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 12, 2014

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
@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 10, 2015

Fixed as part of #896 (thanks @jhance!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant