comparison of PartitionTuples
I find this issue with the coercion model for PartitionTuples
confusing:
sage: P = PartitionTuples(level=2)
sage: P((p,p)) in P
True
sage: (p,p) in P
True
sage: P((p,p)) == (p,p)
False
However as FrédericC notes below we have
sage: P((p,p)) == [p,p]
True
Implementing _richcmp_
and __richcmp__
both in the element and in the category does not solve this issue as they are never called. Also in the list case if one tries to compare directly using _cmp_
or their rich versions we'd get an exception. So I guess the comparison is happening at the Python level as follows:
sage: S = (p,p,p)
sage: T = P(S)
sage: L = [p,p,p]
sage: T.__eq__(S)
False
sage: T.__eq__(L)
True
But
Probably caused by the absence of a specific
_richcmp_
for partition tuples.It's a little more complicated than that. I've implemented _richcmp_ directly in the element class and in the category elementmethods and it never gets called. I figured it is because first
Element
tries to coerce. So I implemented__richcmp__
and still its never called. Same for_cmp_
and__cmp__
. Calling directlycoercion_model.richcmp((p,p), P(p,p), op_EQ)
as expected givesFALSE
. I'll update the question with your remark as wellperhaps reimplementing
__eq__
in the class, but that could lead to lots of problems elsewhere so I decided against it