Run some code in a string and return the result Args: code_define (str): the code that does imports, function definitions, etc code_run (str): the one line whose result you want to output.
(code_define: str, code_run: str)
| 130 | |
| 131 | |
| 132 | def run_code(code_define: str, code_run: str) -> Any: |
| 133 | """ |
| 134 | Run some code in a string and return the result |
| 135 | |
| 136 | Args: |
| 137 | code_define (str): the code that does imports, function definitions, etc |
| 138 | code_run (str): the one line whose result you want to output. |
| 139 | """ |
| 140 | # adding the wrapper function is needed to get the imports to work |
| 141 | # add indentation |
| 142 | code_define = "\n ".join(code_define.split("\n")) |
| 143 | code_run = code_run.strip("\n") |
| 144 | wrapper_fn = """ |
| 145 | def wrapper(): |
| 146 | %s |
| 147 | |
| 148 | return %s |
| 149 | """ % ( |
| 150 | code_define, |
| 151 | code_run, |
| 152 | ) |
| 153 | exec(wrapper_fn) |
| 154 | return eval("wrapper()") |
| 155 | |
| 156 | |
| 157 | def check_conditions(condition_registry: list[dict], code_registry: dict[str, dict]): |
no outgoing calls
no test coverage detected