summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Marie <sylvain.marie@schneider-electric.com>2018-10-26 14:38:40 +0200
committerSylvain Marie <sylvain.marie@schneider-electric.com>2018-10-26 14:38:40 +0200
commit63fe9fa1f74beb7af5c0badb061d0688416cbc12 (patch)
treeb3ba69afb4f30fe45ffe93d14f1f6ad795efca54
parent230964fbc941263c9371a3de4196f43f72792e11 (diff)
downloadpython-decorator-git-63fe9fa1f74beb7af5c0badb061d0688416cbc12.tar.gz
Fixed issue with coroutines in python 3.5: indeed unfortunately they appear as generator functions in python 3.5.
-rw-r--r--src/decorator.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/decorator.py b/src/decorator.py
index ccb2204..4433abf 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -236,7 +236,18 @@ def decorate(func, caller, extras=()):
ex = '_e%d_' % i
evaldict[ex] = extra
es += ex + ', '
- if isgeneratorfunction(caller):
+
+ if not ('3.5' <= sys.version < '3.6'):
+ create_generator = isgeneratorfunction(caller)
+ else:
+ # With Python 3.5: apparently isgeneratorfunction returns
+ # True for all coroutines
+
+ # However we know that it is NOT possible to have a generator
+ # coroutine in python 3.5: PEP525 was not there yet.
+ create_generator = isgeneratorfunction(caller) and not iscoroutinefunction(caller)
+
+ if create_generator:
fun = FunctionMaker.create(
func, "for res in _call_(_func_, %s%%(shortsignature)s):\n"
" yield res" % es, evaldict, __wrapped__=func)