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

Function remove_unindented_lines

evalplus/lecacy_sanitize.py:23–47  ·  view source on GitHub ↗
(
    code: str, protect_before: str, execeptions: List[str], trim_tails: List[str]
)

Source from the content-addressed store, hash-verified

21
22
23def remove_unindented_lines(
24 code: str, protect_before: str, execeptions: List[str], trim_tails: List[str]
25) -> str:
26 lines = code.splitlines()
27 cut_idx = []
28 cut_enabled = False
29 for i, line in enumerate(lines):
30 if not cut_enabled and line.startswith(protect_before):
31 cut_enabled = True
32 continue
33 if line.strip() == "":
34 continue
35 if any(line.startswith(e) for e in execeptions):
36 continue
37
38 lspace = len(line) - len(line.lstrip())
39 if lspace == 0:
40 cut_idx.append(i)
41
42 if any(line.rstrip().startswith(t) for t in trim_tails):
43 # cut off everything behind
44 cut_idx.extend(list(range(i, len(lines))))
45 break
46
47 return "\n".join([line for i, line in enumerate(lines) if i not in cut_idx])
48
49
50def to_four_space_indents(old_code):

Callers 1

sanitizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected