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

Function get_contract_and_ref

tools/humaneval/init_plus.py:49–81  ·  view source on GitHub ↗
(task_id: int, entry_point)

Source from the content-addressed store, hash-verified

47
48
49def get_contract_and_ref(task_id: int, entry_point) -> Tuple[str, str]:
50 mod = import_module(f"groundtruth.humaneval.{str(task_id).zfill(3)}_{entry_point}")
51 fn = getattr(mod, entry_point)
52
53 doc = fn.__doc__
54 if task_id == 51:
55 doc = doc.replace("bcdf\nghjklm", r"bcdf\nghjklm").replace(
56 "abcdef\nghijklm", r"abcdef\nghijklm"
57 )
58
59 code = (
60 getsource(fn).replace(doc, "").replace("''''''", '""""""').split('""""""\n')[-1]
61 )
62
63 assert code, f"Something wrong with {task_id}!"
64 assert code[:3] != "def", f"Something wrong with the {task_id}!"
65
66 # split code to contract and impl
67 contract = ""
68 impl = ""
69
70 reading_contract = True
71 for line in code.strip("\n").split("\n"):
72 if reading_contract and "$_CONTRACT_$" in line:
73 contract += line + "\n"
74 else:
75 reading_contract = False
76 impl += line + "\n"
77
78 if contract:
79 contract = "\n" + contract
80
81 return contract, "\n" + impl + "\n"
82
83
84def get_atol(task_id: int) -> float:

Callers 1

init_plus.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…