On 16 October 2017 at 21:08, Juancarlo Añez <apal...@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:
>
> https://github.com/neogeny/TatSu/blob/master/tatsu/contexts.py
>
>
> 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).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to