summaryrefslogtreecommitdiff
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
parent8dd2913bc310e02084c9a7eee81187c53d7bd1e8 (diff)
downloadpython-decorator-git-c517358ff0a14c6b15914e2969fe17a76c276917.tar.gz
Removed the need for 2to3
-rw-r--r--setup.py16
-rw-r--r--src/decorator.py19
2 files changed, 14 insertions, 21 deletions
diff --git a/setup.py b/setup.py
index 1521c3d..2adcffa 100644
--- a/setup.py
+++ b/setup.py
@@ -1,21 +1,14 @@
import sys
import os.path
if sys.version >= '3':
- from setuptools import setup # needed for the flag use_2to3
+ from setuptools import setup
else:
from distutils.core import setup
+dic = {}
+exec(open('src/decorator.py').read(), dic)
+VERSION = dic['__version__']
-def getversion(fname):
- """Get the __version__ reading the file: works both in Python 2.X and 3.X,
- whereas direct importing would break in Python 3.X with a syntax error"""
- for line in open(fname):
- if line.startswith('__version__'):
- return eval(line[13:])
- raise NameError('Missing __version__ in decorator.py')
-
-VERSION = getversion(
- os.path.join(os.path.dirname(__file__), 'src/decorator.py'))
if __name__ == '__main__':
setup(name='decorator',
@@ -39,5 +32,4 @@ if __name__ == '__main__':
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries',
'Topic :: Utilities'],
- use_2to3=True,
zip_safe=False)
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(