
On 27 Jul 2019, at 10:19, Serhiy Storchaka <storchaka@gmail.com> wrote:
26.07.19 23:57, Guido van Rossum пише:
These are interesting ideas. It looks like you intend the except clause of the for loop to *only* cover the iter() and next() calls that are implicit in the for loop. You're right that it's awkward to catch exceptions there.
Right. If you want to catch an exception in the loop body you have to wrap the loop body with "try ... except". If you want to catch an exception in the loop body *and* the 'for' clause you have to wrap the whole "for" statement with "try ... except". No new syntax is needed for this. But if you want to catch an exception *only* in the 'for' clause you can't (without getting rid of the "for" statement at all).
However, I worry that when people see this syntax, they will think that the except clause is for handling exceptions in the loop body. (That's certainly what I assumed when I read just your subject line. :-)
I think people can make a mistake only when they see it for the first time. After you learn what this syntax means, you will not make this mistake the second time. The same applies to any other syntactic construction.
I don't think that's correct. I know many people who have learned what for-else does and promptly forgot it because it doesn't make sense to them. I'm fairly certain I know what it does after having this discussion many many times but I'm not 100% sure. If something reads one way and is in reality something else it's super hard to not read it as the plain meaning. In the for-else case it could have been "for.. on not break" (and "on empty", "on break", and such) and it would be very nice. I'm supportive of the proposal but not the syntax. / Anders