Message244386
I just noticed that I hadn't used the real "types.coroutine" in my Py3.5 tests when reporting back in issue 24017. When I pass a Cython generator through it, I get
"""
Traceback (most recent call last):
File "tests/run/test_coroutines_pep492.pyx", line 245, in test_coroutines_pep492.CoroutineTest.test_func_5 (test_coroutines_pep492.c:13445)
for el in bar():
File "/opt/python3.5/lib/python3.5/types.py", line 197, in wrapped
'non-coroutine: {!r}'.format(coro))
TypeError: callable wrapped with types.coroutine() returned non-coroutine: <generator object at 0x7f178c458898>
"""
This is actually obvious, given that the sole purpose of the decorator is to turn something that is a Generator and *not* a Coroutine into something that is a Coroutine, as a means for the user to say "but I know better". So checking for the return value being a Coroutine is wrong. Instead, it should check that it's a Generator and if it's not an Awaitable, wrap it as a self-returning Awaitable. That's more or less what my proposed implementation in issue 24017 did:
class types_coroutine(object):
def __init__(self, gen):
self._gen = gen
class as_coroutine(object):
def __init__(self, gen):
self._gen = gen
self.send = gen.send
self.throw = gen.throw
self.close = gen.close
def __await__(self):
return self._gen
def __call__(self, *args, **kwargs):
return self.as_coroutine(self._gen(*args, **kwargs)) |
|
Date |
User |
Action |
Args |
2015-05-29 15:41:41 | scoder | set | recipients:
+ scoder, gvanrossum, ncoghlan, python-dev, yselivanov |
2015-05-29 15:41:41 | scoder | set | messageid: <1432914101.1.0.793326929089.issue24316@psf.upfronthosting.co.za> |
2015-05-29 15:41:41 | scoder | link | issue24316 messages |
2015-05-29 15:41:40 | scoder | create | |
|