Skip to content
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

Surprising non-failure with return type #1753

Closed
russel opened this issue Jun 27, 2016 · 4 comments
Closed

Surprising non-failure with return type #1753

russel opened this issue Jun 27, 2016 · 4 comments

Comments

@russel
Copy link

russel commented Jun 27, 2016

The code:

def _validate(x:int) -> int:
    if not isinstance(x, int):
        raise TypeError('Argument must be an integer.')
    if x < 0:
        raise ValueError('Argument must be a non-negative integer.')

does not return an error with the mypy 0.4.2 that appeared in the Debian Sid repository for a while (*). The inference is that the None return is being treated as an int, which is a bit surprising.

Obviously I had intended to have:

def _validate(x:int):
    if not isinstance(x, int):
        raise TypeError('Argument must be an integer.')
    if x < 0:
        raise ValueError('Argument must be a non-negative integer.')

which also passes the mypy test.

(*) Does anyone know why the mypy package has been removed from the Debian Sid repository?

@sharmaeklavya2
Copy link

I tested this code with the latest development snapshot of mypy with the --strict-optional option but it still doesn't report any error.

@sharmaeklavya2
Copy link

@russel see #1450.

@gvanrossum
Copy link
Member

gvanrossum commented Jun 27, 2016 via email

@rwbarton
Copy link
Contributor

Yes, it's #1229; closing as duplicate of that issue.

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

No branches or pull requests

4 participants