def check_nesting(self, **kwargs):
"""Inspect the code for too much nested expressions."""
try:
max_nesting = kwargs['max_nesting']
except KeyError:
return
# Traverse the nodes and find those that are nested
# (have 'body' attribute).
nodes = [(node, node.lineno) for node
in ast.walk(self.parsed_code.body[0])
if hasattr(node, 'body')]
nesting_level = len(nodes)
if nesting_level > max_nesting:
# The line number where the error was found
# is the next one (thus + 1):
line_number = nodes[-1][1] + 1
self.issues[line_number].add(
self.code_errors.nesting_too_deep(
nesting_level, max_nesting
)
)
评论列表
文章目录