[Python-ideas] try-else without except or finally
Nick Coghlan
ncoghlan at gmail.com
Mon Nov 14 23:38:40 CET 2011
On 11/15/11, Chris Kaynor <ckaynor at zindagigames.com> wrote:
> On Mon, Nov 14, 2011 at 11:34 AM, Matt Joiner <anacrolix at gmail.com> wrote:
>> So I maintain that the else block could be made allowable even without
>> an except block, but it would be purely for convenience. I don't think
>> it's worth it anymore.
>
> While it is redundant to allow else without except, I would agree that
> it should be allowed for the same reason that else is allowed on for
> and while without a break. The alternative would be to make the later
> illegal. Either seems reasonable, however the former maintains
> backwards compatibility, while the later breaks it.
This change is *not going to happen*. Guido said drop it. Every core
developer in the conversation said drop it. Please let the thread die
already.
The fact that 'else:' is allowed on loops without a break statement
(despite such a construct being pointless) is just a way to simplify
the language compilation process. While it obviously could be detected
and prevented if we really wanted to (since we basically do that to
allow 'yield' to alter the meaning of a function definition), reaching
inside a suite to detect that kind of thing is a pain and simply not
worth the hassle in this specific case. If it really bothers you,
propose a patch to pyflakes (etc) that issues a warning for this kind
of error (assuming they don't detect it already).
In no way, shape or form does the fact we allow a particular redundant
construct because detecting it is a pain to implement justify relaxing
the parsing rules to allow an equally redundant construct that all
compliant Python implementations *already* reject (and is much easier
to detect in the first place, since the required precursor is a peer
suite rather than a statement embedded inside such a suite).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list