MCPcopy Create free account
hub / github.com/ChartGalaxy/ChartGalaxy / fix_list_format

Function fix_list_format

code_understanding/scoring.py:14–29  ·  view source on GitHub ↗

Standardize string representations of lists, adding quotes around elements if missing, and safely evaluate to Python list. Returns original item if parsing fails.

(item: str)

Source from the content-addressed store, hash-verified

12 return predictions
13
14def fix_list_format(item: str) -> Any:
15 """
16 Standardize string representations of lists, adding quotes around elements if missing,
17 and safely evaluate to Python list. Returns original item if parsing fails.
18 """
19 if not isinstance(item, str):
20 return item
21 match = re.match(r"^\[(.*)\]$", item.strip())
22 if not match:
23 return item
24 content = match.group(1)
25 corrected = re.sub(r"(?<!['\w])(\w[^,]*?)(?!['\w])", r"'\1'", content)
26 try:
27 return ast.literal_eval(f"[{corrected}]")
28 except (SyntaxError, ValueError):
29 return item
30
31
32def parse_to_list(text: str) -> Optional[List[str]]:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected