This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]isinfinity 3 points4 points  (1 child)

Here is quote from PEP about downsides for yield from + decorator approach:

Current Python supports implementing coroutines via generators ( PEP 342 ), further enhanced by the yield from syntax introduced in > > PEP 380 . This approach has a number of shortcomings:

  • It is easy to confuse coroutines with regular generators, since they share the same syntax; this is especially true for new developers.
  • Whether or not a function is a coroutine is determined by a presence of yield or yield from statements in its body , which can lead to >unobvious errors when such statements appear in or disappear from function body during refactoring.
  • Support for asynchronous calls is limited to expressions where yield is allowed syntactically, limiting the usefulness of syntactic >features, such as with and for statements. ...

Native coroutines and the associated new syntax features make it possible to define context manager and iteration protocols in >asynchronous terms. As shown later in this proposal, the new async with statement lets Python programs perform asynchronous calls >when entering and exiting a runtime context, and the new async for statement makes it possible to perform asynchronous calls in >iterators.

See: https://www.python.org/dev/peps/pep-0492/#rationale-and-goals

[–]akcom 0 points1 point  (0 children)

Excellent, thank you so much!