diff --git a/fastcore/xtras.py b/fastcore/xtras.py index cfefb052..463cd9db 100644 --- a/fastcore/xtras.py +++ b/fastcore/xtras.py @@ -417,8 +417,8 @@ def exec_eval(code, # Code to exec/eval "Evaluate `code` in `g` (defaults to `globals()`) and `l` (defaults to `locals()`)" import ast, inspect frame = inspect.currentframe().f_back - if l is None: l = g if g else frame.f_locals if g is None: g = frame.f_globals + if l is None: l = g tree = ast.parse(code, mode='exec') if tree.body and isinstance(tree.body[-1], ast.Expr): *statements, expr = tree.body diff --git a/nbs/03_xtras.ipynb b/nbs/03_xtras.ipynb index ed1d042b..a34af337 100644 --- a/nbs/03_xtras.ipynb +++ b/nbs/03_xtras.ipynb @@ -1799,8 +1799,8 @@ " \"Evaluate `code` in `g` (defaults to `globals()`) and `l` (defaults to `locals()`)\"\n", " import ast, inspect\n", " frame = inspect.currentframe().f_back\n", - " if l is None: l = g if g else frame.f_locals\n", " if g is None: g = frame.f_globals\n", + " if l is None: l = g\n", " tree = ast.parse(code, mode='exec')\n", " if tree.body and isinstance(tree.body[-1], ast.Expr):\n", " *statements, expr = tree.body\n",