Skip to content

Instantly share code, notes, and snippets.

@lwzm
Last active January 2, 2019 10:48
Show Gist options
  • Save lwzm/9756992 to your computer and use it in GitHub Desktop.
Save lwzm/9756992 to your computer and use it in GitHub Desktop.
eval_orig = eval
def patch_eval():
if eval is not eval_orig:
return False
from functools import lru_cache
c = lru_cache(maxsize=1000)(compile)
e = eval_orig
def _eval(expr, globals=None, locals=None):
return e(c(expr, expr[:30], "eval"), globals, locals)
import builtins
builtins.eval = _eval
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment