Coding style.

- Minor shortening of python_gut.
This commit is contained in:
Andrew Hamilton 2021-11-06 13:41:04 +10:00
parent b4b237ec1f
commit 90078f5d32

View file

@ -335,15 +335,11 @@ def python_coverage(path):
def _function_body_lines(python_source): def _function_body_lines(python_source):
ranges = [] ranges = []
class FuncNodeVisitor(ast.NodeVisitor): class FuncNodeVisitor(ast.NodeVisitor):
def _line_range(self, body): def _line_range(self, body):
return body[0].lineno - 1, body[-1].end_lineno return body[0].lineno - 1, body[-1].end_lineno
def visit_FunctionDef(self, node): def visit_FunctionDef(self, node):
ranges.append(self._line_range(node.body)) ranges.append(self._line_range(node.body))
visit_AsyncFunctionDef = visit_FunctionDef
def visit_AsyncFunctionDef(self, node):
ranges.append(self._line_range(node.body))
tree = ast.parse(python_source) tree = ast.parse(python_source)
FuncNodeVisitor().visit(tree) FuncNodeVisitor().visit(tree)
return ranges return ranges