Created
March 6, 2025 12:41
-
-
Save whynotavailable/424ab3d599a5dfaf5b6a731ee7f33655 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def safe_extract(expr: str, globals: typing.Dict[str, typing.Any]): | |
| tree = ast.parse(expr, mode="eval") | |
| code = compile(tree, filename="<ast>", mode="eval") | |
| return eval(code, globals=globals) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment