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

Functions annotated to return None can't return function calls returning None #2828

Closed
TRManderson opened this issue Feb 8, 2017 · 7 comments

Comments

@TRManderson
Copy link
Contributor

Minimal example:

def fn1() -> None:
    return None

def fn2() -> None:
    return fn1() # test.py:5: error: No return value expected

Sorry for the poor issue naming, not sure how else to describe this.

@TRManderson
Copy link
Contributor Author

One of the tests explicitly disallows this, which is the cause for my PR #2829 failing. I've removed it in the PR, but is there a reason to have it there in the first place?

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 24, 2017

I have a feeling that this has been discussed earlier. Anyway, it's a matter of style -- the code is clearly correct. I wonder if @gvanrossum has an opinion whether fn2 should be accepted.

@gvanrossum
Copy link
Member

I'm torn, since I sometimes do this myself, but I do think it's a (very slight) code smell. I also think that fn1() and fn2() should either both be errors or both pass (both have a -> None and a return EXPR where EXPR is known to have the value None).

@ddfisher
Copy link
Collaborator

For what it's worth, this is allowed with --strict-optional.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 28, 2017

If it's only a very slight code smell, mypy should perhaps not complain about it.

@gvanrossum
Copy link
Member

gvanrossum commented Feb 28, 2017 via email

@msullivan
Copy link
Collaborator

This is fixed

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

No branches or pull requests

5 participants