Skip to content

assert and isinstance type inference #475

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 · 2 comments
Closed

assert and isinstance type inference #475

JukkaL opened this issue Oct 12, 2014 · 2 comments
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 12, 2014

This code should be accepted by mypy:

def f(x: Union[int, str]) -> None:
    assert isinstance(x, int)
    x + 1  # type of x is int, so this should be okay

The type type checker should know about type assertions.

@JukkaL JukkaL added the feature label Oct 12, 2014
@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 12, 2014

This could sometimes be used as an arguably more Pythonic replacement for casts.

@gvanrossum
Copy link
Member

I found a bunch of occurrences of this in our server code; bumping priority to 0.3.2.

ddfisher added a commit to ddfisher/mypy that referenced this issue Apr 8, 2016
gvanrossum pushed a commit that referenced this issue Apr 8, 2016
* Get type information from isinstance assertions

Fixes #475.

* Add test
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

2 participants