On Wed, Sep 6, 2017 at 11:26 PM, Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > Guido van Rossum wrote: >> >> This feels like a very abstract argument. I have a feeling that context >> state propagating out of a call is used relatively rarely -- it must work >> for cases where you refactor something that changes context inline into a >> utility function (e.g. decimal.setcontext()), but I just can't think of a >> realistic example where coroutines (either of the yield-from variety or of >> the async/def form) would be used for such a utility function. > > > Yuri has already found one himself, the __aenter__ and __aexit__ > methods of an async context manager.
__aenter__ is not a generator and there's no 'yield from' there. Coroutines (within an async task) leak state just like regular functions (within a thread). Your argument is to allow generators to leak context changes (right?). AFAIK we don't use generators to implement __enter__ or __aenter__ (generators decorated with @types.coroutine or @asyncio.coroutine are coroutines, according to PEP 492). So this is irrelevant. > >> A utility function that sets context state but also makes a network call >> just sounds like asking for trouble! > > > I'm coming from the other direction. It seems to me that it's > not very useful to allow with-statements to be skipped in > certain very restricted circumstances. Can you clarify what do you mean by "with-statements to be skipped"? This language is not used in PEP 550 or in Python documentation. I honestly don't understand what it means. > > The only situation in which you will be able to take advantage > of this is if the context change is being made in a generator > or coroutine, and it is to apply to the whole body of that > generator or coroutine. > > If you're in an ordinary function, you'll still have to use > a context manager. If you only want the change to apply to > part of the body, you'll still have to use a context manager. > > It would be simpler to just tell people to always use a > context manager, wouldn't it? Yes, PEP 550 wants people to always use a context managers! Which will work as you expect them to work for coroutines, generators, and regular functions. At this point I suspect you have some wrong idea about some specification detail of PEP 550. I understand what Koos is talking about, but I really don't follow you. Using the "with-statements to be skipped" language is very confusing and doesn't help to understand you. Yury _______________________________________________ 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