According to https://www.python.org/dev/peps/pep-0492/#id31:

  The [types.coroutine] function applies CO_COROUTINE flag to
  generator-function's code object, making it return a coroutine
  object.

Further down in https://www.python.org/dev/peps/pep-0492/#id32:

   [await] uses the yield from implementation with an extra step of
   validating its argument. await only accepts an awaitable,
   which can be one of:

     ...

     - A generator-based coroutine object returned from a generator
       decorated with types.coroutine().

If I'm understanding this correctly, type.coroutine's only purpose is to add
a flag to a generator object so that await will accept it.

This raises the question of why can't await simply accept a generator
object?  There is no code change to the gen obj itself, there is no
behavior change in the gen obj, it's the exact same byte code, only a
flag is different.

types.coroutine feels a lot like unnecessary boiler-plate.

--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to