Hey Simon,

>> Isn't that a total mess? Is there a reason why UniqueRepresentation 
> >> provides __eq__ and __hash__, but not __cmp__? 
> >> 
> > 
> > I thought __cmp__() is only called if __eq__() is not implemented? 
>
> I did not check the documentation before writing the following, but I 
> think it is as follows: 
>  * If you do A==B then __eq__ is called, regardless of whether __cmp__ 
>    is provided or not. 
>  * Your class will implicitly have __eq__, __le__, __ne__ and so on, 
>    if you implement __richcmp__ 
>  * If you do not implement  __richcmp__ but you implement __cmp__ then 
>    again your class will implicitly have __eq__, __le__, ... 
>  * If you provide both __richcmp__ and __cmp__, then your __richcmp__ 
>    will be used in A==B, A<=B etc., but your __cmp__ will be used in 
>    cmp(A,B). 
>
> And now the catch: In a Cython class, you can not directly implement 
> __eq__, but you *must* implement __richcmp__ instead.


That seems strange to me...
 

> And that's a 
> problem when cythoning UniqueRepresentation, because currently it is a 
> Python class with __eq__, __ne__ and __hash__ implemented, but not with 
> __richcmp__. 
>
> And the problem with UniqueRepresentation.__richcmp__ is that one has an 
> obvious default for __eq__ and __ne__ (namely comparison with "is" or 
> "is not"), but __le__ and other comparison must be provided in another 
> class, because there is no obvious default. 
>

Okay. Is there any reason why we couldn't default to comparing the string 
representation because I would think we would not want two different 
(unique) parents to have the same repr and it would give a consistent 
return?


> > I almost feel like we should try to push comparisons by "is" (identity) 
> > rather than  "==" (equality) for unique parents. 
>
> Well, that is what UniqueRepresentation.__eq__ does anyway. 
>

Point. I was thinking in the same way as None.

> Also please forgive the naive question, but is there any reason for a 
> > Parent to not be a UniqueRepresentation? 
>
> For a very simple reason: If your Parent is a cdef class then it simply 
> can not inherit from UniqueRepresentation, because it is a Python class. 
>
> This problem will not be lifted. Even though I will try to provide a 
> cythoned UniqueRepresentation.__richcmp__ method, it would be impossible 
> to turn the Python class UniqueRepresentation into a cdef class: It 
> relies on a metaclass, and that's not available for extension classes. 
>

Ah I see. That explains a few things I was curious about. Thanks!

Thank you,
Travis

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to sage-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-devel+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to