Skip to content

Commit

Permalink
fix exec_eval globals
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Oct 25, 2024
1 parent fe31209 commit 686ccc1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nbs/03_xtras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 686ccc1

Please sign in to comment.