summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2017-07-23 11:07:49 +0200
committerMichele Simionato <michele.simionato@gmail.com>2017-07-23 11:07:49 +0200
commitbdc76f0c7bcd011324b6001acc166c9e90593b00 (patch)
tree4f3e720e445e870533c9e437c15574e23799bb5d
parenta4b6dc28a709c98f071c8061429840ac371d70a1 (diff)
downloadpython-decorator-git-bdc76f0c7bcd011324b6001acc166c9e90593b00.tar.gz
Now the coroutine signature is determined by the caller
-rw-r--r--src/decorator.py7
-rw-r--r--src/tests/test.py1
2 files changed, 4 insertions, 4 deletions
diff --git a/src/decorator.py b/src/decorator.py
index aa09566..58e120a 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -223,7 +223,8 @@ class FunctionMaker(object):
func = obj
self = cls(func, name, signature, defaults, doc, module)
ibody = '\n'.join(' ' + line for line in body.splitlines())
- if self.coro:
+ caller = evaldict.get('_call_') # when called from `decorate`
+ if caller and iscoroutinefunction(caller):
body = ('async def %(name)s(%(signature)s):\n' + ibody).replace(
'return', 'return await')
else:
@@ -263,9 +264,9 @@ def decorator(caller, _func=None):
else: # assume caller is an object with a __call__ method
name = caller.__class__.__name__.lower()
doc = caller.__call__.__doc__
- evaldict = dict(_call_=caller, _decorate_=decorate)
+ evaldict = dict(_call=caller, _decorate_=decorate)
return FunctionMaker.create(
- '%s(func)' % name, 'return _decorate_(func, _call_)',
+ '%s(func)' % name, 'return _decorate_(func, _call)',
evaldict, doc=doc, module=caller.__module__,
__wrapped__=caller)
diff --git a/src/tests/test.py b/src/tests/test.py
index d882418..fdc3727 100644
--- a/src/tests/test.py
+++ b/src/tests/test.py
@@ -92,7 +92,6 @@ class ExtraTestCase(unittest.TestCase):
@d1
def f1(x, y, z):
pass
-
self.assertNotEqual(d1.__code__.co_filename, d2.__code__.co_filename)
self.assertNotEqual(f1.__code__.co_filename, f2.__code__.co_filename)
self.assertNotEqual(f1_orig.__code__.co_filename,