linfo2335-programming-parad.../project-3/regex/flaw_6.py

25 lines
495 B
Python

import re
def detect_print_instead_of_return(code):
regex = re.compile(
r"def .+:.*\n(?P<indent> +)\S.*(?:\n(?P=indent)(?:(?P<return> *return.*)|(?P<print> *print\(.*)|.*))+",
re.MULTILINE,
)
result = regex.search(code)
if not result:
return False
if result.group("return"):
return False
if not result.group("print"):
return False
# print("Flaw 6: Print instead of return")
# print(result.group(0))
return True