solution.py 文件源码

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

项目:Python-FMI 作者: TsHristov 项目源码 文件源码
def check_lines_per_function(self, **kwargs):
        """
           Inspect the code for too many lines
           per function/method.
        """
        try:
            max_lines = kwargs['max_lines_per_function']
        except KeyError:
            return
        function_definition = self.parsed_code.body[0]
        if not isinstance(function_definition, ast.FunctionDef):
            return
        code_lines = self.code.splitlines()[1:]
        # Filter out the lines, which do
        # not consist only of whitespaces:
        logic_lines = len(list(filter(lambda line:
                          line != re.search('\s+', line).group(),
                          code_lines)))
        if logic_lines > max_lines:
            line_number = function_definition.lineno
            self.issues[line_number].add(
                self.code_errors.too_many_lines(
                    logic_lines, max_lines)
                )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号