solution.py 文件源码

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

项目:Python-FMI 作者: TsHristov 项目源码 文件源码
def check_indentation(self, **kwargs):
        """Inspect the code for indentation size errors."""
        try:
            indentation_size = kwargs['indentation_size']
        except KeyError:
            # Use the default value instead:
            indentation_size = self.DEFAULT_RULES['indentation_size']
        # Traverse the nodes and find those that are nested
        # (have 'body' attribute).
        nodes = [node for node in ast.walk(self.parsed_code.body[0])
                 if hasattr(node, 'body')]
        # Use the previous line offset
        # as a guide for the next line indentation.
        last_offset = 0
        for node in nodes:
            line_number = node.body[0].lineno
            col_offset = node.body[0].col_offset
            if col_offset > last_offset + indentation_size:
                offset = col_offset - last_offset
                self.issues[line_number].add(
                    self.code_errors.indentation(offset, indentation_size)
                )
            last_offset = col_offset
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号