[Python-ideas] SyntaxWarning for for/while/else without break or return?
Steven D'Aprano
steve at pearwood.info
Fri Oct 9 04:28:09 CEST 2009
On Thu, 8 Oct 2009 08:59:21 pm Stefan Rank wrote:
> In the return-but-no-break-example I had in mind::
>
> def findit(bag):
> for elem in bag:
> if isgreat(elem):
> return elem
> else:
> return default
>
> the use of else, though correct and arguably readable, is still
> unnecessary.
We should raise UnnecessaryNotActuallyAnError then.
There is lots of code which is correct and readable while still
unnecessary. Should we ban these too?
mylist.extend([])
flag = True and flag
if (flag is True) is True:
...
while False:
...
if True:
...
elif False:
...
[item for item in seq if True]
alist.sort(key=lambda x: x)
and so forth. Just think, with a bit of imagination we can slow the
compiler down by a factor of two, three or even ten, by prohibiting all
sorts of perfectly legal code!
--
Steven D'Aprano
More information about the Python-ideas
mailing list