[Python-ideas] PEP 355 (overloading boolean operations) and chained comparisons

Nick Coghlan ncoghlan at gmail.com
Thu Oct 20 00:27:20 CEST 2011


On Thu, Oct 20, 2011 at 6:25 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:
> In a way, the and/or/not overloading suggestion is worse
> than rich comparisons because even the simplest
> "a and b" expression would have to be compiled in
> a profoundly different way (and the related peephole
> optimizations would not longer be valid).  Everyone
> would pay the price.

Indeed. I actually think adding '&&' and '||' for the binary logical
operator purposes described in PEP 355 would be a preferable
alternative to messing with the meaning of 'and' and 'or' as flow
control expressions. The meaning of chained comparisons could then
also be updated accordingly so that "a < b < c" translated to "a < b
&& b < c" if the result of "a < b" overloaded the logical and
operation, but would still short circuit otherwise.

I'm not saying I think that's necessarily a *good* idea - I'm just
saying I dislike it less than the approach currently proposed by the
PEP.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list