I sent this message earlier but it was rejected by the mailer.

On Fri, Jul 26, 2019 at 11:27 AM Serhiy Storchaka <storch...@gmail.com>
wrote:

>
> So you will be able to add errors handling like in:
>
>      with connect() as stream:
>          for data in stream:
>              try:
>                  write(data)
>              except OSError:
>                  handle_write_error()
>          except OSError:
>              handle_read_error()
>      except OSError:
>          handle_connection_error()
>

To put this in a simpler way: the proposal is to add an except clause that
applies ONLY to the direct operation of the with or for statement and not
to the block. That's an interesting idea.

The one thing I find confusing about your proposal is that the proposed
syntax does not imply the behavior. In a try statement, the except appears
at the end and after all possible statements that it could cover. The
proposal mimics that syntax but with different semantics. Something like
this would be much more clear what is going on:

    for VARIABLE in EXPRESSION:
        except EXCEPTION:
            BLOCK
        BLOCK

    with EXPRESSION as VARIABLE:
        except EXCEPTION:
            BLOCK
        BLOCK

    while EXPRESSION:
        except EXCEPTION:
            BLOCK
        BLOCK

or rewriting your example:

    with connect() as stream:
        except OSError:
            handle_connection_error()
        for data in stream:
            except OSError:
                handle_read_error()
            try:
                write(data)
            except OSError:
                handle_write_error()
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/RTZTO5I4LYCRQXVI3H75RCU4Q4NCPOXT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to