Was: Is this an Bug in python 2.3?? Reflective relational operators

Grégoire Dooms dooms at info.LESS.ucl.SPAM.ac.be
Tue Jun 15 17:08:30 CEST 2004


Balaji wrote:
> Hello Everybody...
> 
> Let me try to explain what do I mean by "ordering importance".
> 
> In our application a expression 100>=x reads as 100 is an upper bound
> on x. Mathematically it is same as saying x<=100 which also bounds x
> by 100. But in modelling, the user wants to preserve the order in
> which he has written the expression.
> 
> If the left side of an operand is an immutable type then this ordering
> is no longer preserved, even if both the methods are implemented(i.e
> __le__ and __ge__).
> 

No, as far as I understand the doc, if the left side does not support 
comparing to your instance on the left then your instance's reversed 
operator method is called.

> __radd__ allows you to have an immutable type on the left side. An
> __rge__ method would provide the same functionality for relational
> operators.
> 
> Is there a way to obtain this behavior with current syntax? 
I far as I know, there is no __rge__ and no possible way to detect if 
ian op was called from either syntax.
The comparison operators should be used in cases where the "reflective" 
behaviour is sound. I beleive they should not be used for other things 
than comparing instances for witch there is a complete order (many 
others will disagree).

--
Grégoire Dooms



More information about the Python-list mailing list