Constraints on __sub__, __eq__, etc.
Robert Kern
robert.kern at gmail.com
Thu Feb 18 11:39:53 EST 2010
On 2010-02-18 10:19 AM, Andrey Fedorov wrote:
> It seems intuitive to me that the magic methods for overriding the +, -,
> <, ==, >, etc. operators should have no sideffects on their operands.
> Also, that == should be commutative and transitive, that > and < should
> be transitive, and anti-commutative.
>
> Is this intuition written up in a PEP, or assumed to follow from the
> mathematical meanings?
Some of it is covered in the reference manual. E.g.
http://docs.python.org/reference/datamodel.html#object.__lt__
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list