Feature suggestion -- return if true

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Apr 12 20:03:34 EDT 2011


On Tue, 12 Apr 2011 16:48:31 -0700, Ethan Furman wrote:

> Westley Martínez wrote:
>> On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote:
>>> --> def func():
>>> -->     var1 = something()
>>> -->     var2 = something_else('this') -->     return?
>>> var1.hobgle(var2)
>>> -->     var3 = last_resort(var1)
>>> -->     return var3.wiglat(var2)
>> 
>> The question mark makes the programmer look like he wasn't sure of what
>> he was doing at the time.  "Hmm, should I return this object or not?"
>> 
>> 
> Yeah, I'm definitely -1 on the ?, as well as -1 on the idea.  All other
> major flow control uses indentation, and this does not.

Neither return nor raise use indentation, and you don't get much more 
major than those. Nor do list comps or generator expressions.

Indentation is not appropriate here because it doesn't involve a block of 
code. The whole point is that it just involves a single expression.

But in any case, I'm -1 on any syntax involving ? in Python, and +0 on 
the concept on a conditional return. I suspect it's too specialised to be 
worth special syntax or a keyword, but I can definitely see some uses for 
it.



-- 
Steven



More information about the Python-list mailing list