MCPcopy Index your code
hub / github.com/evalplus/evalplus / code_extract

Function code_extract

evalplus/sanitize.py:30–44  ·  view source on GitHub ↗
(text: str)

Source from the content-addressed store, hash-verified

28
29
30def code_extract(text: str) -> str:
31 lines = text.split("\n")
32 longest_line_pair = (0, 0)
33 longest_so_far = 0
34
35 for i in range(len(lines)):
36 for j in range(i + 1, len(lines)):
37 current_lines = "\n".join(lines[i : j + 1])
38 if syntax_check(current_lines):
39 current_length = sum(1 for line in lines[i : j + 1] if line.strip())
40 if current_length > longest_so_far:
41 longest_so_far = current_length
42 longest_line_pair = (i, j)
43
44 return "\n".join(lines[longest_line_pair[0] : longest_line_pair[1] + 1])
45
46
47def get_deps(nodes: List[Tuple[str, Node]]) -> Dict[str, Set[str]]:

Callers 3

test_code_extractFunction · 0.90
sanitizeFunction · 0.85

Calls 1

syntax_checkFunction · 0.90

Tested by 1

test_code_extractFunction · 0.72