Spaces:
Sleeping
Sleeping
Download server/tasks/task_medium.py from luciferai-devil/code-debug-env: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/spaces/luciferai-devil/code-debug-env/resolve/main/server/tasks/task_medium.py
- Command line
-
hf download hf://spaces/luciferai-devil/code-debug-env/server/tasks/task_medium.py
-
curl -L -o task_medium.py https://huggingface.co/spaces/luciferai-devil/code-debug-env/resolve/main/server/tasks/task_medium.py
2.14 kB
| # server/tasks/task_medium.py | |
| TASK_MEDIUM = { | |
| "task_id": "task_medium", | |
| "difficulty": "medium", | |
| "num_tests": 6, | |
| "description": ( | |
| "Fix two independent bugs in the `parse_key_value` function. " | |
| "It should parse a string of 'key=value' pairs separated by semicolons " | |
| "into a dictionary. Bug 1: it splits on the wrong delimiter for pairs. " | |
| "Bug 2: it doesn't strip whitespace from keys and values." | |
| ), | |
| # The broken version the agent sees | |
| "buggy_code": """\ | |
| def parse_key_value(s: str) -> dict[str, str]: | |
| \"\"\"Parse 'key1=val1;key2=val2' into {'key1': 'val1', 'key2': 'val2'}. | |
| Handles whitespace around keys/values. Returns empty dict for empty string.\"\"\" | |
| if not s or not s.strip(): | |
| return {} | |
| result = {} | |
| # BUG 1: splits on ',' instead of ';' | |
| pairs = s.split(',') | |
| for pair in pairs: | |
| if '=' not in pair: | |
| continue | |
| key, value = pair.split('=', 1) | |
| # BUG 2: missing .strip() on key and value | |
| result[key] = value | |
| return result | |
| """, | |
| "clean_code": """\ | |
| def parse_key_value(s: str) -> dict[str, str]: | |
| \"\"\"Parse 'key1=val1;key2=val2' into {'key1': 'val1', 'key2': 'val2'}. | |
| Handles whitespace around keys/values. Returns empty dict for empty string.\"\"\" | |
| if not s or not s.strip(): | |
| return {} | |
| result = {} | |
| pairs = s.split(';') | |
| for pair in pairs: | |
| if '=' not in pair: | |
| continue | |
| key, value = pair.split('=', 1) | |
| result[key.strip()] = value.strip() | |
| return result | |
| """, | |
| "test_suite": """\ | |
| def test_basic(): | |
| assert parse_key_value("name=Alice;age=30") == {"name": "Alice", "age": "30"} | |
| def test_whitespace(): | |
| assert parse_key_value(" name = Alice ; age = 30 ") == {"name": "Alice", "age": "30"} | |
| def test_empty(): | |
| assert parse_key_value("") == {} | |
| def test_single_pair(): | |
| assert parse_key_value("key=value") == {"key": "value"} | |
| def test_value_with_equals(): | |
| assert parse_key_value("expr=a=b;other=c") == {"expr": "a=b", "other": "c"} | |
| def test_whitespace_only(): | |
| assert parse_key_value(" ") == {} | |
| """, | |
| } | |