[Python-ideas] Revisiting dedicated overloadable boolean operators

Michel Desmoulin desmoulinmichel at gmail.com
Thu Aug 9 13:04:22 EDT 2018


Adding one operator is hard in Python.

Adding 4 operators, just for the sake of a bit of syntaxic suggar for
DSL based projects is never going to fly.

And I say that as a long time SQLA user.

Le 03/08/2018 à 19:46, Todd a écrit :
> Coming back to the previous discussion about a new set of overloadable
> boolean operators [1], I have an idea for overloadable boolean operators
> that I think might work.  The idea would be to define four new operators
> that take two inputs and return a boolean result based on them.  This
> behavior can be overridden in appropriate dunder methods.  These
> operators would have similar precedence to existing logical operators. 
> The operators would be:
> 
> bNOT - boolean "not"
> bAND - boolean "and"
> bOR - boolean "or"
> bXOR - boolean "xor"
> 
> With corresponding dunder methods:
> 
> __bNOT__ and _rbNOT__ (or __r_bNOT__)
> __bAND__ and _rbAND__ (or __r_bAND__)
> __bOR__ and _rbOR__ (or __r_bOR__)
> __bXOR__ and _rbXOR__ (or __r_bXOR__)
> 
> The basic idea is that the "b" is short for "boolean", and we change the
> rest of the operator to upercase to avoid confusions with the existing
> operators.  I think these operators would be preferably to the proposals
> so far (see [1] again) for a few reasons:


More information about the Python-ideas mailing list