solution.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Python-FMI 作者: TsHristov 项目源码 文件源码
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
                )
            )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号