Proposed new conditional operator: "or else"

Chris Angelico rosuav at gmail.com
Tue Dec 2 13:12:57 EST 2014


On Wed, Dec 3, 2014 at 4:41 AM, Zachary Ware
<zachary.ware+pylist at gmail.com> wrote:
> On Tue, Dec 2, 2014 at 11:18 AM, Roy Smith <roy at panix.com> wrote:
>> Wouldn’t it be neat to write:
>>
>>    foo == 42 or else
>>
>> and have that be an synonym for:
>>
>>     assert foo == 42
>>
>> :-)
>
> Never going to happen, but I like it!  Perhaps raise IntimidationError
> instead of AssertionError when it fails?

Definitely. That's what I first thought, when I saw the subject line.

Additionally, whenever this construct is used, the "yield" statement
(expression, whatever) will be redefined to yield to intimidation and
make the statement true, whatever it takes. In the above example,
"yield" would decide which out of foo and 42 is more amenable to
change, and altering it to be equal to the other. (It may also find
that == is the most amenable, and alter its definition such that foo
and 42 become equal.)

ChrisA



More information about the Python-list mailing list