timeit

Програмиране с Python

Курс във Факултета по Математика и Информатика към СУ

Решение на Статичен анализ на python код от Вера Бойчева

Обратно към всички решения

Към профила на Вера Бойчева

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importast
import re

def trailing_whitespaces(code, result):
    line = 0
    for rule in rules:
        line = line + 1
        if re.match(r'\w*\s+$'):
            result['trailing_whitespaces'] = line

def deep_nesting(code, allowed_nests,  result):
    parsed_code = ast.parse(code)
    for parsed_part in parsed_code.body:
        if count("FunctionDef", str(parsed_part)) > allowed_nests:
            result["asd"] = 1
    return 'hello world'

def long_lines(code, limit, result):
    splitted_code = code.split('\n')
    line = 0
    for row in splitted_code:
        line = line + 1
        if len(row) > 10:
            result[ 'trailing_whitespaces'] = line
                        
def critic(code, **rules):
    result = {}
    for rule in rules:
        if rule == 'line too long':
            long_lines(code, rules[rule], result)
        elif rule == 'trailing spaces' and rules[rule] == True:
            trailing_whitespaces(code, result)

Лог от изпълнението

name 'importast' is not defined
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 114, in main
    loaded_test = imp.load_source('test', test_module)
  File "/usr/local/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/tmp/d20160709-29474-fn6v9q/test.py", line 3, in <module>
    import solution
  File "/tmp/d20160709-29474-fn6v9q/solution.py", line 1, in <module>
    importast

История (3 версии и 0 коментара)

Вера обнови решението на 18.05.2016 16:55 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
importast
import re


def deep_nesting(code, allowed_nests,  result):
    parsed_code = ast.parse(code)
    for parsed_part in parsed_code.body:
        if count("FunctionDef", str(parsed_part)) > allowed_nests:
            result["asd"] = 1
    return 'hello world'

def long_lines(code, limit, result):
    splitted_code = code.split('\n')
    line = 0
    for row in splitted_code:
        line = line + 1
        if len(row) > 10:
            result[ 'trailing_whitespaces'] = line
                        
def critic(code, **rules):
    result = {}
    for rule in rules:
        if rule == 'line too long':
            long_lines(code, rules[rule], result)
        elif rule == 'trailing spaces' and rules[rule] == True:
            trailing_spaces(code, result)

Вера обнови решението на 18.05.2016 16:59 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importast
import re

def trailing_whitespaces(code, result):
    line = 0
    for rule in rules:
        line = line + 1
        if re.match(r'\w*\s+$'):
            result['trailing_whitespaces'] = line

def deep_nesting(code, allowed_nests,  result):
    parsed_code = ast.parse(code)
    for parsed_part in parsed_code.body:
        if count("FunctionDef", str(parsed_part)) > allowed_nests:
            result["asd"] = 1
    return 'hello world'

def long_lines(code, limit, result):
    splitted_code = code.split('\n')
    line = 0
    for row in splitted_code:
        line = line + 1
        if len(row) > 10:
            result[ 'trailing_whitespaces'] = line
                        
def critic(code, **rules):
    result = {}
    for rule in rules:
        if rule == 'line too long':
            long_lines(code, rules[rule], result)
        elif rule == 'trailing spaces' and rules[rule] == True:
            trailing_spaces(code, result)

Вера обнови решението на 18.05.2016 16:59 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
importast
import re

def trailing_whitespaces(code, result):
    line = 0
    for rule in rules:
        line = line + 1
        if re.match(r'\w*\s+$'):
            result['trailing_whitespaces'] = line

def deep_nesting(code, allowed_nests,  result):
    parsed_code = ast.parse(code)
    for parsed_part in parsed_code.body:
        if count("FunctionDef", str(parsed_part)) > allowed_nests:
            result["asd"] = 1
    return 'hello world'

def long_lines(code, limit, result):
    splitted_code = code.split('\n')
    line = 0
    for row in splitted_code:
        line = line + 1
        if len(row) > 10:
            result[ 'trailing_whitespaces'] = line
                        
def critic(code, **rules):
    result = {}
    for rule in rules:
        if rule == 'line too long':
            long_lines(code, rules[rule], result)
        elif rule == 'trailing spaces' and rules[rule] == True:
            trailing_whitespaces(code, result)