Proposed new conditional operator: "or else"

Tim Chase python.list at tim.thechases.com
Tue Dec 2 13:30:00 EST 2014


On 2014-12-02 11:41, Zachary Ware 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?

In light of the parallel thread discussing the "assert" statement
and the perils of trusting it to be present even though it can be
optimized away, this "or else" could be (in the altered words of Don
Corleone), "I'm gonna make an assertion he can't refuse."

(not that I particularly want/expect this in the language definition,
but it's fun to entertain the idea)

-tkc






More information about the Python-list mailing list