Completed
Push — master ( 649ac2...ddd162 )
by Amresh
02:57 queued 01:22
created

fastest.code_assets.function   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 14
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_functions() 0 18 1
A get_functions_from_node() 0 5 1
1
import ast
2
3
from fastest.code_assets.naive_case_detector import get_test_from_example_passage
4
5
6
7
def get_functions_from_node(node):
8
    return [{
9
        'name': n.name,
10
        'tests': get_test_from_example_passage(ast.get_docstring(n))
11
    } for n in node.body if isinstance(n, ast.FunctionDef)]
12
13
14
def get_functions(page):
15
    """
16
    ------
17
    examples:
18
    @let
19
    page = 'def f(): return 1'
20
    @end
21
22
    1) get_functions(page) -> [{'name': 'f', 'tests': None}]
23
    ------
24
    :param page:
25
    :return:
26
    """
27
    node = ast.parse(page)
28
    functions = get_functions_from_node(node)
29
    classes = [n for n in node.body if isinstance(n, ast.ClassDef)]
30
    methods = [get_functions_from_node(class_) for class_ in classes]
31
    return functions + methods
32