/home/simon/sage/src/sage/structure/richcmp.pyx in 
sage.structure.richcmp.richcmp_by_eq_and_lt.richcmp 
(build/cythonized/sage/structure/richcmp.c:2172)()
    317             if equal_types:
    318                 other_eq = getattr(other, eq_attr)
--> 319             if other_eq(self):
    320                 return rich_to_bool(op, 0)
    321             if op == Py_EQ:

TypeError: unbound method _eq_() must be called with 
FreeModule_ambient_field_with_category instance as first argument (got 
FreeModule_submodule_field_with_category instance instead)

probably there should be 
319        if other.other_eq(self)
or maybe
319        other.__eq__(self)

Also when having many different subclasses which have to compare this 
lt_by_eq_and_lt does not work. As it gives the comparison to the other 
element all the time. But I think that is really something that the user 
should decide in his code if he wants it. This does too much.
For me this resulted in circular references etc... so it was a pain to get 
it work.

        if not equal_types:
            try:
                other_eq = getattr(other, eq_attr)
                other_lt = getattr(other, lt_attr)


On Friday, October 20, 2017 at 3:59:17 AM UTC+2, Simon Brandhorst wrote:
>
> Well richcmp allows you to define just one method. But it does not save 
> you any work at all if the order is partial. 
> Because then you have to distinguish the cases op = op_LE , op_GE, op_LT 
> ... etc. .... so all that you save is documentation and everything is more 
> obscure.
>
> I also tried the richcmp_by_eq_and_lt in principle it is a nice idea and 
> exactly what I need.
> In practice it does not work. Well I could get it to work and all doctests 
> in the free_module.py and free_quadratic_module.py passed. But when testing 
> the whole module folder everything exploded.
> With commit b59062520b9b8e99e8ee126cbf209feb241a596a
>
>     TypeError: _eq_() takes exactly 2 arguments (1 given)
>     TypeError: unbound method _eq_() must be called with 
> FreeModule_submodule_pid_with_category instance as first argument (got 
> FreeModule_submodule_with_basis_pid_with_category instance instead)
>     TypeError: unbound method _eq_() must be called with 
> FreeModule_submodule_field_with_category instance as first argument (got 
> FreeModule_submodule_with_basis_field_with_category instance instead)
> etc. etc. 
>
> So my solution was to remove the @richcmp decorator and the richcmp_by_eq 
> method. Then implement __neq__, __geq__ __leq__ by hand. 
> You can see it in #23978.
>
> It needs review :).
>
> So I expect that the richcmp_by_eq_and_lt does not work properly?
> Also lt is harder to implement they le. That would be nice to have too?
>
> On Tuesday, October 17, 2017 at 8:13:59 PM UTC+2, Travis Scrimshaw wrote:
>>
>>
>>
>> On Tuesday, October 17, 2017 at 9:55:25 AM UTC-5, Simon Brandhorst wrote:
>>>
>>> I got that now. But at the time I thought __richcmp__ was just a fancy 
>>> new name for the old __cmp__ in python in order to make it python 3 
>>> compatible. 
>>>
>>> Anyways. It would be nice to say something like that in the 
>>> documentation. (Maybe I have just missed it and it is there already.)
>>> "
>>> @richcmp_method simply allows to define just 
>>> one comparison method __richcmp__ instead of six __eq__, __lt__, ... "
>>> "
>>> and add a reference to some working example somewhere in the sage 
>>> library.
>>> As many people will come across that file who are not programmers and do 
>>> not speak cython.
>>> And in future they will also not know about the __cmp__ method of python 
>>> 2.7
>>>
>>> In Python, those are called rich comparisons and returning 
>> NotImplemented is a Python thing for rich comparisons, including in things 
>> like __eq__. So it doesn't have to do with speaking Cython. IMO, anytime 
>> you want to find an example in the Sage library, grep is your friend and is 
>> more robust than in some place in the documentation that could (quickly) go 
>> out of date. However, I agree with you that the documentation could be 
>> improved by stating about returning NotImplemented and having a more 
>> complete example.
>>
>> Best,
>> Travis
>>
>>  
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to