Feature suggestion -- return if true

Grant Edwards invalid at invalid.invalid
Mon Apr 11 22:18:47 EDT 2011


On 2011年04月12日, James Mills <prologic at shortcircuit.net.au> wrote:
> On Tue, Apr 12, 2011 at 11:44 AM, Grant Edwards <invalid at invalid.invalid> wrote:
>> How is that the same?
>>>> ??return? something() ?? ?? ?? ?? ?? ?? ?? ?? ??return something() or None
>> ??return? somethingelse() ?? ?? ?? ?? ?? ?? ??return somethingelse() or None
>> ??log("didn't find an answer") ?? ?? ?? ?? log("didn't find an answer")
>> ??raise ValueError ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? raise ValueError
>>>> Are you saying the two snippets above are equivalent?
>> def foo(n):
> x = n < 5
> if x:
> return x
>> is functionally equivalent to:
>> def foo(n):
> return n < 5

That's not what I asked.
You stated that
 return? <expr>
was equivalent to
 return <expr> or None
If that was the case then the two code snippets _I_ posted should be
equivalent:
 return? something() return something() or None
 return? somethingelse() return somethingelse() or None
 log("didn't find an answer") log("didn't find an answer")
 raise ValueError raise ValueError
If the two snipped above are not equivalent, then
 return? <expr>
is isn't equivalent to
 return <expr> or None
-- 
Grant


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /