Proto-PEP: Overloadable Boolean Operators

Alex Martelli aleaxit at yahoo.com
Mon Sep 6 03:24:04 EDT 2004


greg <greg at cosc.canterbury.ac.nz> wrote:
   ...
> Python does not currently provide any '__xxx__' special methods
> corresponding to the 'and', 'or' and 'not' boolean operators. In the
   ...
> There is no such difficulty in the case of 'not', however, and it

Indeed, that's what the strangely-named __nonzero__ special method does:
it's invoked upon the 'not' operator and in no other case, so it would
be strange to claim it's anything but "a special method corresponding to
the 'not' boolean operator".  Problem is, __nonzero__ is currently
typechecked -- it has to return an integer.  Maybe relaxing that
constraint might be enough for 'not' (while your elaborate proposals may
well be necessary for 'and' & 'or').


Alex



More information about the Python-list mailing list