[Python-ideas] SyntaxWarning for for/while/else without break or return?

Stephen J. Turnbull stephen at xemacs.org
Sat Oct 10 10:57:14 CEST 2009


Gerald Britton writes:

 > Well I guess you can read the post how you like.  Based on the way
 > Python works today, I'm sure you won't get a warning for people
 > failing to read the documentation.

The point is giving warnings for constructs that are sufficiently
confusing, even having read the documentation, or typoable (in Emacs,
the difference between

    for thing in iterable:
        if thing.is_good():
            break
        else:
            thing = default_thing()

and

    for thing in iterable:
        if thing.is_good():
            break
    else:
        thing = default_thing()

is one DEL when typing the code).  Whether it's worth doing it for
this construct is marginal to me, but I find those who advocate it to
be giving plausible arguments.

And you really ought to stop posting and let Steven d'Aprano carry the
flag.<wink>  Given *your* record of repeatedly explaining the semantics
incorrectly when you have clearly read the documentation, for-else
qualifies on the criterion above.  The others on your list don't,
especially since most of them have nearly identical semantics to the
preferred form, and at least one (#4) is not currently possible to
implement.




More information about the Python-ideas mailing list