Import a function by exec. Args: statements: Python statements Returns: Function-wrapped value of `f`. Raises: ValueError: the statements didn't define a value for "f"
(statements)
| 205 | |
| 206 | |
| 207 | def Import(statements): |
| 208 | """Import a function by exec. |
| 209 | |
| 210 | Args: |
| 211 | statements: Python statements |
| 212 | |
| 213 | Returns: |
| 214 | Function-wrapped value of `f`. |
| 215 | |
| 216 | Raises: |
| 217 | ValueError: the statements didn't define a value for "f" |
| 218 | """ |
| 219 | environ = {} |
| 220 | exec_(statements, environ) |
| 221 | if "f" not in environ: |
| 222 | raise ValueError("failed to define \"f\": %s", statements) |
| 223 | f = environ["f"] |
| 224 | return Function(f) |
| 225 | |
| 226 | |
| 227 | # pylint: enable=invalid-name, exec-used |