Feature suggestion -- return if true

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Apr 12 12:52:24 CEST 2011


On Tue, 12 Apr 2011 16:21:43 +1000, James Mills wrote:

> On Tue, Apr 12, 2011 at 4:08 PM, Nobody <nobody at nowhere.com> wrote:
>> It should be abundantly clear that this only returns if the expression
>> is considered true, otherwise it continues on to the following
>> statements.
> 
> Uggh come on guys. We've been over this. You cannot make that
> assumption.

The code snippet is absolutely clear. It is ordinary Python code:

_temp = expr
if _temp: return _temp

You should notice the lack of "else: return None" in that code snippet.

The only assumption being made is that the OP means what he says.

I suppose you can assume that he means something else if you like, but 
then you have no possible way of knowing what he actually means ("well, I 
*said* conditional return, but I *meant* BEGIN and END delimiters like in 
Pascal...").

Personally, I like the idea of a conditional return, but I *hate* the 
proposed syntax. But I don't think it's useful enough to deserve a new 
keyword either.



-- 
Steven



More information about the Python-list mailing list