This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients gvanrossum, ncoghlan, python-dev, scoder, yselivanov
Date 2015-05-29.15:41:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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/", 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:41scodersetrecipients: + scoder, gvanrossum, ncoghlan, python-dev, yselivanov
2015-05-29 15:41:41scodersetmessageid: <>
2015-05-29 15:41:41scoderlinkissue24316 messages
2015-05-29 15:41:40scodercreate