I think the focus shouldn't be on whether such syntax is possibly confusing or
not because
a) People will always remember that's *either* one way or the other, but are
very unlikely to just assume one; hence they can always check what it does, and
more importantly,
b) It's actually pretty easy to remember which way it is, by just considering
that a syntax feature exists for scenarios that can't be easily solved
otherwise. For `for ... else` it's actually more tricky than for the proposed
syntax because that doesn't let you distinguish between "`else` is only
executed if the loop didn't `break`" and "`else` is only executed if the loop
didn't execute at all". But for `for ... except` or `while ... except` it will
be even more obvious because `try ... except`ing the body is just as easy as,
well, `try ... except`ing the body; it's pretty clear that no new syntax would
be required for that and hence it must concern the statement itself since
that's not easy to work around.
The only possible confusion I see is when people look at something like this:
for ...:
LENGTHY BODY
except ...:
HANDLER
else:
SOMETHING_ELSE
and only look at the `except ... else` part and readily assume that the two are
complementary. But that's easy to prevent by only allowing the opposite order,
i.e. `for ... else ... except`, stressing that the two are unrelated in this
case.
In the end a feature should be driven by its usefulness to the community and
whether it provides a solution for an otherwise (hard|awkward)-to-solve
problem. I could imagine that due to the awkward workaround, especially
regarding `with`, corresponding "self-made" code is either error-prone or
people will not even try to work around it in the first place. This feature
will probably be among the less prominent ones, but someone who needs it will
be glad that it exists and they're also likely to be well aware of what it does
(just like with `for ... else`). Someone who encounters that feature for the
first time, e.g. when reviewing some code, will probably check what it does and
even if not, the assumption that it `except`s the whole body should be
perplexing since (a) excepting whole blocks by default is not really best
practice and (b) it's pretty easy to accomplish that with existing syntax.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/JIHFJT5XGBKBQZWSJNIEAORJ5LI2LT7T/
Code of Conduct: http://python.org/psf/codeofconduct/