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

Cannot detect when function returns None but should return int #4587

Closed
hvnsweeting opened this issue Feb 19, 2018 · 1 comment
Closed

Cannot detect when function returns None but should return int #4587

hvnsweeting opened this issue Feb 19, 2018 · 1 comment

Comments

@hvnsweeting
Copy link
Contributor

hvnsweeting commented Feb 19, 2018

  • Are you reporting a bug, or opening a feature request?
    Bug

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

# mypytrueneg.py
def hello2():
    # type: () -> int
    return None


def hello():
    # type: () -> None
    return 1
  • What is the actual behavior/output?
 $ mypy mypytrueneg.py
mypytrueneg.py:8: error: No return value expected
  • What is the behavior/output you expect?
    mypy should detect that hello2 returns None and it is not int as statically type declared.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

$ python --version
Python 3.5.2

$ mypy --version
mypy 0.560

Also tried
$ mypy --version
mypy 0.570-dev-b0af822a79465a93d55e67b5aea74551a63c08f4
@JukkaL
Copy link
Collaborator

JukkaL commented Feb 19, 2018

By default, None is considered compatible with everything. You can run mypy with --strict-optional and it will catch the error.

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

2 participants