Hi, I am defining a parent and elements in the category of modules over QQ. The proper way would be to use the category framework:
from sage.structure.parent import Parent from sage.structure.element import ModuleElement from sage.categories.modules import Modules class MElement(ModuleElement): def __init__(self, parent, x): ModuleElement.__init__(self, parent) self._x = x def _repr_(self): return 'element {}'.format(self._x) def _rmul_(self, e): # defines scalar multiplication R = self.parent() return R.element_class(R, e * self._x) class M(Parent): Element = MElement def __init__(self): Parent.__init__(self, base=QQ, category=Modules(QQ)) Then the following works fine: sage: P = M() sage: five = P.element_class(P, 5); five element 5 sage: 2 * five element 10 My question is: why should I use `ModuleElement` instead of just `Element`? If I use `Element`, the scalar multiplication is not detected by the coercion system. So I am forced to use `ModuleElement`. Since my parent is in the category of modules over QQ, then I think elements of the parent should be automatically treated as module elements, and using `Element` should just be ok. What do you think? -- 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.