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

21 lines
384 B
Python
Raw Permalink Normal View History

2024-05-23 14:47:20 +02:00
import re
def detect_unused_loop_variable(code):
regex = re.compile(
r"^(?P<indent> *)for (?P<id>\S+) in .+:(?:\n(?P=indent) +((?P<contains>[^#\n]*(?P=id).*)|.*))*",
re.MULTILINE,
)
result = regex.search(code)
if not result:
return False
if result.group("contains"):
return False
# print(result.group(0))
return True