On Sun, Mar 22, 2015 at 5:16 PM, Joachim Durchholz <j...@durchholz.org> wrote:
> Am 22.03.2015 um 22:23 schrieb Aaron Meurer:
>>
>> Python operations fallback to the reverse operation when they are not
>> defined, so e.g., x + y does x.__add__(y) and if that returns
>> NotImplemented, it does y.__radd__(x).  For the comparison operators,
>> it does the flipped operator, so this would be (0).__le__(x + 3),
>> which returns NotImplemented, so it then calls (x + 3).__ge__(0),
>> which works.
>
>
> Good to know - I was suspecting that that's the case, but wasn't 100% sure.
> Is this behaviour documented somewhere? I didn't find any reference to it,
> but maybe I'm looking in the wrong spots.

https://docs.python.org/3/reference/datamodel.html#object.__lt__. That
page in general is a good reference for all these sorts of things.

Aaron Meurer

>
>> The only downside here is that you end up getting
>>
>> inequality in the reversed order from what you wanted.
>
>
> No big deal as long as all comparison functions are implemented
> consistently, I suppose.
> Do I suppose correctly?
>
> Ah, one trap: Consistency has to be ensured across classes. Not difficult
> but requires diligence and quite precise knowledge about Python's comparison
> semantics.
> Any other traps?
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/550F3F36.7090109%40durchholz.org.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BjEzqXtSqkUXcpyw25dW-X199w6KjkeTEKoNHnMg5xBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to