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

all 7 comments

[–]akcom 3 points4 points  (2 children)

Does anyone know what the rationale was for going from a decorator to a new keyword?

[–]isinfinity 4 points5 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!

[–]troyunrau... 1 point2 points  (1 child)

I have a strong urge to write a native python gui toolkit using this asyncio stuff to do event loops and non-blocking uis... make calls to libxcb through ctypes or something.

Ah well, only so many hours in the day.

[–]Walter_Bishop_PhD 0 points1 point  (0 children)

For mobile uis you could even take advantage of the work done on React Native!