I'm looking through my RC file and I can't for the life of me, find which one of these variables disables that feature.
I searched for "if", "else" and "return" and I didn't see anything. Unless I've missed it.
Thanks.
More Info
pylint 1.7.2,
astroid 1.5.3
Python 2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
What I'm putting into the terminal
pylint --rcfile=.pylintrc Test.py
Test code
""" Module Docstring """
def IS_POSITIVE(number):
""" detects positive """
if number > 0:
return "+++"
else:
return "---"
print IS_POSITIVE(3)
The print out
************* Module Test
R: 27, 4: Unnecessary "else" after "return" (no-else-return)
------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 8.00/10, +0.00)
This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.
At the time of writing this, the Mozilla Coding Style guidelines have this recommendation under “General C/C++ Practices”: Don't put an else right after a return. Delete the else, it's unnecessary and increases indentation level.
you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.
It's just saying that there's no need for 'else' since the execution of the function already stopped and if the 'if' condition doesn't succeed, it will still run any code underneath it.
In this particular case you could be better off using a ternary operator.
def is_positive(number):
return "+++" if number > 0 else "---"
You should add no-else-return
to the comma separated list of disabled options in the disable
setting in your .pylintrc
file.
Also see the Pylint docs:
http://pylint.pycqa.org/en/latest/technical_reference/features.html#messages-control-options
You are looking for no-else-return (R1705)
. Just add these to your .pylintrc
:
[REFACTORING]
no-else-return=no
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With