-
Notifications
You must be signed in to change notification settings - Fork 752
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
Consistent use of "return None" in functions #399
Comments
Thanks, I saw this discussion and this helps remind me to implement it. :) |
First attempt to implement new check about consistent returns. PEP 8 has been updated accordingly (cf GvR message). Implementation is still perfectible on many points. Also, I've changed many details here and there that are not relevant for the issue. Finally, I'll need to double-check the error number.
fwiw, import math
def foo(x: float) -> float:
if x >= 0:
return math.sqrt(x)
def bar(x: float) -> float:
if x < 0:
return
return math.sqrt(x) $ mypy --check-untyped-defs t.py
t.py:3: error: Missing return statement
t.py:9: error: Return value expected
Found 2 errors in 1 file (checked 1 source file) |
Quite a lot of work has been spent on this issue but not much actual progress what integrated.
These questions come from discussions over various PRs:
Having gone way too far is the AST check direction, I can see the troubles it leads to and think it may be just easier to consider that #711 is probably as good as things can be. |
I, for one, am of the mind that people should be using pylint in addition to flake8 and other tools. In light of the fact that pylint has support for this, is there urgency in us figuring out the right way to do this? For one thing, I'd rather as few false positives as possible. I wonder if, because this is an AST concern, if we can just write this as something that acts as an AST plugin for Flake8 (maybe one already exists?) |
Could you add this rule to pep8? I just updated the official PEP 8 to include this (I'm surprised it wasn't already there):
function should return an expression, or none of them should. If any return
statement returns an expression, any return statements where no value is
returned should explicitly state this as return None, and an explicit
return statement should be present at the end of the function (if
reachable).
https://mail.python.org/pipermail/python-dev/2015-April/139054.html
The text was updated successfully, but these errors were encountered: