Skip to content

Commit

Permalink
really fix func_globals on Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Apr 23, 2015
1 parent 4801783 commit 470ca5c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions numbagg/transform.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import inspect
import re
import sys

PY2 = sys.version_info[0] < 3

def _get_globals(f):
# fall back to Python 2 attribute
return getattr(f, '__globals__', f.func_globals)

def _func_globals(f):
return f.func_globals if PY2 else f.__globals__


def _apply_source_transform(func, transform_source):
Expand All @@ -16,7 +18,7 @@ def _apply_source_transform(func, transform_source):
orig_source = inspect.getsource(func)
source = transform_source(orig_source)
scope = {}
exec(source, _get_globals(func), scope)
exec(source, _func_globals(func), scope)
try:
return scope['__transformed_func']
except KeyError:
Expand Down

0 comments on commit 470ca5c

Please sign in to comment.