summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura M?dioni <laura.medioni@logilab.fr>2015-11-03 14:43:26 +0100
committerLaura M?dioni <laura.medioni@logilab.fr>2015-11-03 14:43:26 +0100
commitc63ec9cc702161e23db13b3b2397289904073274 (patch)
tree6eca78f68a509045ceebb3d298d8e2478cf0c597
parentf039b5e6bd46256c2299223bca68c03f3fc241a3 (diff)
downloadpylint-c63ec9cc702161e23db13b3b2397289904073274.tar.gz
some more comments for too-many-nested-blocks rule implementation
related to the issue #668
-rw-r--r--pylint/checkers/base.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index d8bbdf6..7a2e408 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -1705,7 +1705,9 @@ class ElifChecker(BaseTokenChecker):
@check_messages('too-many-nested-blocks')
def leave_functiondef(self, node):
+ # new scope = reinitialize the stack of nested blocks
self._nested_blocks = []
+ # if there is a waiting message left, send it
if self._nested_blocks_msg:
self.add_message('too-many-nested-blocks',
node=self._nested_blocks_msg[0],
@@ -1718,6 +1720,8 @@ class ElifChecker(BaseTokenChecker):
# only check block levels inside functions or methods
if not isinstance(node.scope(), astroid.FunctionDef):
return
+ # messages are triggered on leaving the nested block. Here we save the
+ # stack in case the current node isn't nested in the previous one
nested_blocks = self._nested_blocks[:]
if node.parent == node.scope():
self._nested_blocks = [node]
@@ -1740,6 +1744,9 @@ class ElifChecker(BaseTokenChecker):
self.config.max_nested_blocks))
self._nested_blocks_msg = None
else:
+ # if time has not come yet to send the message (ie the stack of
+ # nested nodes is still increasing), save it in case the
+ # current node is the last one of the function
self._nested_blocks_msg = (self._nested_blocks[0],
(len(self._nested_blocks),
self.config.max_nested_blocks))