[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.

Jean-Michel Pichavant

2/18/2010 4:59:00 PM

Andrey Fedorov wrote:
>
> It may be intuitive to you, but its not true, written down
> anywhere, nor assumed by the language, and the mathematical
> meaning of the operators doesn't matter to Python. Python
> purposefully does not enforce anything for these methods.
>
>
> Right, so neither is anything in PEP-8, but it's still considered
> "good practice". I'm running across examples like you gave (__sub__
> having a side-effect on the left-hand operand) in some code, and am
> trying to find concrete justification for avoiding it.
>
> - Andrey

This is all about communication. Python allows you to call a cat a dog.
You'll confuse everyone if you do so, but you can do it.
If your '-' operator is doing something else than returning the sub
result, it's your call, but do not expect people to get it easily. You'd
better be good at writting the documentation :-)

JM