Cannot use --never-returning-functions for some functions #4167
Labels
Astroid
Related to astroid
Bug 🪲
Needs astroid Brain 🧠
Needs a brain tip in astroid (then an astroid upgrade)
Needs astroid update
Needs an astroid update (probably a release too) before being mergable
Version
pylint==2.7.2
Dependency
pytest
Steps to reproduce
Create a python file
debug.py
:=>
R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
This message is raised as pylint does not understand that
pytest.exit
raises an exception. Using--never-returning-functions="pytest.exit"
should fix this behavior, however it doesn't:=>
R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)
Expected behavior
pylint debug.py --never-returning-functions="pytest.exit"
should not return an error for the above code.Actual behavior
pylint debug.py --never-returning-functions="pytest.exit"
still gives the error "inconsistent-return-statements"Initial analysis
https://github.com/PyCQA/pylint/blob/master/pylint/checkers/refactoring/refactoring_checker.py#L1362
node.func
is Attribute.exit(attrname='exit', expr=<Name.pytest l.7 at 0x7fab9184d898>)node.func.inferred()[0]
is "Uninferable", as a result there is no value we can set for--never-returning-functions
that would get rid of the error "inconsistent-return-statements".Workaround
By wrapping pytest.exit in another function
pytest_exit
,node.func.inferred()[0]
is now:=>
node.func.inferred()[0].qname()
is "debug.pytest_exit" which we can use to get rid of the error "inconsistent-return-statements":The text was updated successfully, but these errors were encountered: