summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2018-01-23 20:52:15 +0100
committerhippo91 <guillaume.peillex@gmail.com>2018-01-23 20:52:15 +0100
commit992a5f18dbe1f723811b1aa2ee84c78ead753d61 (patch)
tree26fdb6a80576cb973173b9b74ad9a69b2dc8e236
parent0d5faa90ac33adda76a373057e6aeb4b8e110afe (diff)
downloadpylint-git-992a5f18dbe1f723811b1aa2ee84c78ead753d61.tar.gz
Add of four test dealing with if statements and function definition under them
-rw-r--r--pylint/checkers/refactoring.py4
-rw-r--r--pylint/test/functional/inconsistent_returns.py39
-rw-r--r--pylint/test/functional/inconsistent_returns.txt22
3 files changed, 55 insertions, 10 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py
index 4032b6230..1f437799d 100644
--- a/pylint/checkers/refactoring.py
+++ b/pylint/checkers/refactoring.py
@@ -583,7 +583,9 @@ class RefactoringChecker(checkers.BaseTokenChecker):
if isinstance(node, astroid.If):
# if statement is returning if there are exactly two return statements in its
# children : one for the body part, the other for the orelse part
- return_stmts = [self._is_node_return_ended(_child) for _child in node.get_children()]
+ # Do not check if inner function definition are return ended.
+ return_stmts = [self._is_node_return_ended(_child) for _child in node.get_children()
+ if not isinstance(_child, astroid.FunctionDef)]
return sum(return_stmts) == 2
# recurses on the children of the node except for those which are except handler
# because one cannot be sure that the handler will really be used
diff --git a/pylint/test/functional/inconsistent_returns.py b/pylint/test/functional/inconsistent_returns.py
index e8c04f0e9..a6ec2cd1f 100644
--- a/pylint/test/functional/inconsistent_returns.py
+++ b/pylint/test/functional/inconsistent_returns.py
@@ -121,6 +121,15 @@ def bug_1771_with_user_config(var):
else:
return var * 2
+def bug_1794_inner_func_in_if(var):
+ # pylint: disable = no-else-return
+ if var:
+ def _inner():
+ return None
+ return None
+ else:
+ return None
+
# Next ones are not consistent
def explicit_implicit_returns(var): # [inconsistent-return-statements]
if var >= 0:
@@ -199,3 +208,33 @@ def bug_1771_counter_example(var): # [inconsistent-return-statements]
inconsistent_returns_in_nested_function()
else:
return var * 2
+
+def bug_1794_inner_func_in_if_counter_example_1(var): # [inconsistent-return-statements]
+ # pylint: disable = no-else-return
+ if var:
+ def _inner():
+ return None
+ return None
+ else:
+ return
+
+def bug_1794_inner_func_in_if_counter_example_2(var): # [inconsistent-return-statements]
+ # pylint: disable = no-else-return
+ if var:
+ def _inner():
+ return
+ return None
+ else:
+ return
+
+def bug_1794_inner_func_in_if_counter_example_3(var): # [inconsistent-return-statements]
+ # pylint: disable = no-else-return
+ if var:
+ def _inner():
+ return None
+ return None
+ else:
+ def _inner2(var_bis): # [inconsistent-return-statements]
+ if var_bis:
+ return True
+ return
diff --git a/pylint/test/functional/inconsistent_returns.txt b/pylint/test/functional/inconsistent_returns.txt
index 6ce725665..08ce9d7d9 100644
--- a/pylint/test/functional/inconsistent_returns.txt
+++ b/pylint/test/functional/inconsistent_returns.txt
@@ -1,9 +1,13 @@
-inconsistent-return-statements:125:explicit_implicit_returns:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:129:empty_explicit_returns:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:134:explicit_implicit_returns2:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:142:explicit_implicit_returns3:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:150:returns_missing_in_catched_exceptions:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:160:complex_func:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:168:inconsistent_returns_in_nested_function.not_consistent_returns_inner:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:189:bug_1772_counter_example:Either all return statements in a function should return an expression, or none of them should.
-inconsistent-return-statements:197:bug_1771_counter_example:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:134:explicit_implicit_returns:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:138:empty_explicit_returns:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:143:explicit_implicit_returns2:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:151:explicit_implicit_returns3:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:159:returns_missing_in_catched_exceptions:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:169:complex_func:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:177:inconsistent_returns_in_nested_function.not_consistent_returns_inner:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:198:bug_1772_counter_example:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:206:bug_1771_counter_example:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:212:bug_1794_inner_func_in_if_counter_example_1:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:221:bug_1794_inner_func_in_if_counter_example_2:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:230:bug_1794_inner_func_in_if_counter_example_3:Either all return statements in a function should return an expression, or none of them should.
+inconsistent-return-statements:237:bug_1794_inner_func_in_if_counter_example_3._inner2:Either all return statements in a function should return an expression, or none of them should.