summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt3
-rw-r--r--src/decorator.py8
2 files changed, 4 insertions, 7 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 80d9a50..4a9b7b6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,7 +2,8 @@ HISTORY
--------
4.0.5 Fixed a bug signaled by David Goldstein: now you can use the name `f`
- as a keyword argument of decorated functions (2015/11/02)
+ as a keyword argument of decorated functions. Avoid copying the globals,
+ as signaled by Benjamin Patterson (2015/12/09)
4.0.4 Included a patch from Zev Benjamin: now decorated functions play well
with cProfile (2015/09/25)
4.0.3 Added a warning about the memoize example, as requested by Robert
diff --git a/src/decorator.py b/src/decorator.py
index 05f7056..a8c22e7 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -225,9 +225,7 @@ def decorate(func, caller):
"""
decorate(func, caller) decorates a function using a caller.
"""
- evaldict = func.__globals__.copy()
- evaldict['_call_'] = caller
- evaldict['_func_'] = func
+ evaldict = dict(_call_=caller, _func_=func)
fun = FunctionMaker.create(
func, "return _call_(_func_, %(shortsignature)s)",
evaldict, __wrapped__=func)
@@ -258,9 +256,7 @@ def decorator(caller, _func=None):
name = caller.__class__.__name__.lower()
callerfunc = caller.__call__.__func__
doc = caller.__call__.__doc__
- evaldict = callerfunc.__globals__.copy()
- evaldict['_call_'] = caller
- evaldict['_decorate_'] = decorate
+ evaldict = dict(_call_=caller, _decorate_=decorate)
return FunctionMaker.create(
'%s(func)' % name, 'return _decorate_(func, _call_)',
evaldict, doc=doc, module=caller.__module__,