From 470ca5cc6dc303cec130ed656eac12ac7bd57cd4 Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Wed, 22 Apr 2015 19:42:45 -0700 Subject: [PATCH] really fix func_globals on Python 3 --- numbagg/transform.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/numbagg/transform.py b/numbagg/transform.py index d7cb965..6242913 100644 --- a/numbagg/transform.py +++ b/numbagg/transform.py @@ -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): @@ -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: