[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Tue Feb 18 03:19:44 CET 2014


On Tue, Feb 18, 2014 at 1:11 PM, MRAB <python at mrabarnett.plus.com> wrote:
>> def throw(ex):
>>      raise ex
>>
>> some_func(1, 2, (x if x is not None else throw(SyntaxError)) except
>> SyntaxError: pass)
>>
>> So if x is None, it doesn't get passed at all. Useful feature... wordy
>> and clunky spelling... no, I'm now sure that I do not like this. But
>> it's amusing!
>>
> That would be clearer as:
>
>     some_func(1, 2, (x if x is not None else pass))
>
> for some value of "clearer". :-)

That depends on the "if/else pass" syntax also being added. The
convolutions above mean that only "except: pass" is needed. :)

Actually, all it requires is that there be some kind of magic object
called "pass" which is whatever the function's default is. Then it
would behave exactly as described, bar the bit about actually passing
less args - it'd require some sort of default. I'm still not sure it's
a good idea, though :)

ChrisA


More information about the Python-ideas mailing list