Ticket #9429 (needs_work defect)
Undesirable behaviour when deriving from QuotientRingElement
|Reported by:||vbraun||Owned by:||AlexGhitza|
|Cc:||novoselt, robertwb||Work issues:|
All arithmetic operations on QuotientRingElement return a new QuotientRingElement, which is not the desired result for derived classes. Instead one should use self.__class__ to return an instance of the actual type:
sage: from sage.rings.quotient_ring_element import QuotientRingElement sage: class Q(QuotientRingElement): ... pass ... sage: P.<x,y> = PolynomialRing(QQ, 'x, y') sage: Pquo = P.quo(x^3) sage: q = Q(Pquo, x) sage: type(q) <class '__main__.Q'> sage: type(q^2) <class 'sage.rings.quotient_ring_element.QuotientRingElement'>
Expected behaviour: q^2 should have the same (derived) type as q.
I am running into this issue because I want to express cohomology classes on toric varieties as derived classes of QuotientRingElement, see #9326. I'll write the obvious patch and attach it later today.
- Status changed from new to needs_review
- Milestone set to sage-4.5