On 16 October 2017 at 21:08, Juancarlo Añez <apalala@gmail.com> wrote:

Interestingly, thinking about the problem in terms of exception handling flow reminded me of the fact that having a generator-iterator yield while inside a with statement or try/except block is already considered an anti-pattern in many situations, precisely because it means that any exceptions that get thrown in (including GeneratorExit) will be intercepted when that may not be what the author really intended.

It all works fine now: 

So, I have a strong requirement: whatever is decided on this PEP... 

Please don't break it? (or make it illegal) 

The "anti-pattern in many situations" qualifier was there because there are cases where it's explicitly expected to work, and isn't an anti-pattern at all (e.g. when the generator is decorated with contextlib.contextmanager, or when you're using a context manager to hold open an external resource like a file until the generator is closed).

So this wasn't intended as an argument for changing anything - rather, it's about my changing my perspective on how beneficial it would be to have generators default to maintaining their own distinct logical context (which then becomes an argument for *not* changing anything).


Nick Coghlan   |   ncoghlan@gmail.com   |   Brisbane, Australia