summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2015-07-19 06:05:15 +0200
committerMichele Simionato <michele.simionato@gmail.com>2015-07-19 06:05:15 +0200
commitc517358ff0a14c6b15914e2969fe17a76c276917 (patch)
treee7c2331aa3f415edd2f565985a59f97efb73dc65 /src
parent8dd2913bc310e02084c9a7eee81187c53d7bd1e8 (diff)
downloadpython-decorator-git-c517358ff0a14c6b15914e2969fe17a76c276917.tar.gz
Removed the need for 2to3
Diffstat (limited to 'src')
-rw-r--r--src/decorator.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/decorator.py b/src/decorator.py
index ece2488..2e14027 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -31,8 +31,9 @@
Decorator module, see http://pypi.python.org/pypi/decorator
for the documentation.
"""
+from __future__ import print_function
-__version__ = '3.4.1'
+__version__ = '4.0.0'
__all__ = ["decorator", "FunctionMaker", "contextmanager"]
@@ -61,7 +62,7 @@ else:
yield self.defaults
def get_init(cls):
- return cls.__init__.im_func
+ return cls.__init__.__func__
DEF = re.compile('\s*def\s*([_\w][_\w\d]*)\s*\(')
@@ -135,7 +136,7 @@ class FunctionMaker(object):
func.__name__ = self.name
func.__doc__ = getattr(self, 'doc', None)
func.__dict__ = getattr(self, 'dict', {})
- func.func_defaults = getattr(self, 'defaults', ())
+ func.__defaults__ = getattr(self, 'defaults', ())
func.__kwdefaults__ = getattr(self, 'kwonlydefaults', None)
func.__annotations__ = getattr(self, 'annotations', None)
try:
@@ -165,10 +166,10 @@ class FunctionMaker(object):
try:
code = compile(src, '<string>', 'single')
# print >> sys.stderr, 'Compiling %s' % src
- exec code in evaldict
+ exec(code, evaldict)
except:
- print >> sys.stderr, 'Error in generated code:'
- print >> sys.stderr, src
+ print('Error in generated code:', file=sys.stderr)
+ print(src, file=sys.stderr)
raise
func = evaldict[name]
if addsource:
@@ -205,7 +206,7 @@ def decorator(caller, func=None):
decorator(caller, func) decorates a function using a caller.
"""
if func is not None: # returns a decorated function
- evaldict = func.func_globals.copy()
+ evaldict = func.__globals__.copy()
evaldict['_call_'] = caller
evaldict['_func_'] = func
return FunctionMaker.create(
@@ -228,10 +229,10 @@ def decorator(caller, func=None):
fun = getfullargspec(callerfunc).args[0] # first arg
else: # assume caller is an object with a __call__ method
name = caller.__class__.__name__.lower()
- callerfunc = caller.__call__.im_func
+ callerfunc = caller.__call__.__func__
doc = caller.__call__.__doc__
fun = getfullargspec(callerfunc).args[1] # second arg
- evaldict = callerfunc.func_globals.copy()
+ evaldict = callerfunc.__globals__.copy()
evaldict['_call_'] = caller
evaldict['decorator'] = decorator
return FunctionMaker.create(