-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Nonsensical returns are not reported as useless-return
if they are indented
#9449
Labels
Enhancement ✨
Improvement to a component
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
Comments
e-gebes
added
the
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
label
Feb 20, 2024
Agree we could extend the check to the last line of a (potentially nested) try/if/with |
jacobtylerwalls
added
Enhancement ✨
Improvement to a component
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
and removed
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
labels
Feb 20, 2024
These are great examples. For anyone who wants to fix this, the warning is raised from this function: def _check_return_at_the_end(self, node: nodes.FunctionDef) -> None:
"""Check for presence of a *single* return statement at the end of a
function.
"return" or "return None" are useless because None is the
default return type if they are missing.
NOTE: produces a message only if there is a single return statement
in the function body. Otherwise _check_consistent_returns() is called!
Per its implementation and PEP8 we can have a "return None" at the end
of the function body if there are other return statements before that!
"""
if len(self._return_nodes[node.name]) > 1:
return
if len(node.body) <= 1:
return
last = node.body[-1]
if isinstance(last, nodes.Return):
# e.g. "return"
if last.value is None:
self.add_message("useless-return", node=node)
# return None"
elif isinstance(last.value, nodes.Const) and (last.value.value is None):
self.add_message("useless-return", node=node) The docstring refers to another function, |
crazybolillo
added a commit
to crazybolillo/pylint
that referenced
this issue
Mar 9, 2024
Returns inside try or if/else conditions were not being detected as useless. Said nodes are now checked for return statements to ensure their last component is not a useless return as well. Closes pylint-dev#9449.
crazybolillo
added a commit
to crazybolillo/pylint
that referenced
this issue
Mar 9, 2024
Returns inside try or if/else conditions were not being detected as useless. Said nodes are now checked for return statements to ensure their last component is not a useless return as well. Closes pylint-dev#9449.
crazybolillo
added a commit
to crazybolillo/pylint
that referenced
this issue
Mar 14, 2024
Returns inside try or if/else conditions were not being detected as useless. Said nodes are now checked for return statements to ensure their last component is not a useless return as well. Closes pylint-dev#9449.
Pierre-Sassoulas
pushed a commit
that referenced
this issue
Mar 15, 2024
Returns inside try or if/else conditions were not being detected as useless. Said nodes are now checked for return statements to ensure their last component is not a useless return as well. Closes #9449.
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Enhancement ✨
Improvement to a component
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
Maybe more
useless-return
messages should be reported, see the comments in the code snippet.Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: