[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Constraints on __sub__, __eq__, etc.

Benjamin Kaplan

2/18/2010 4:38:00 PM

On Thu, Feb 18, 2010 at 11:19 AM, Andrey Fedorov <anfedorov@gmail.com> 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?
> - Andrey

There are no assumptions about anything. You can do whatever you want
when you implement the functions yourself. For the numeric types, they
follow the intuitive meanings but that's not necessary for user
defined types. Of course, your users will get very confused if a == b
but b != a. Or if a == b and a != b at the same time.


> --
> http://mail.python.org/mailman/listinfo/p...
>
>