Hi, You must bypass the element_class.
1) Convert your base classes to categorized classes using something along Parent P: def ___init__(self): self.element_class_A = self.__make_element_class__(MyElementA) self.element_class_B = self.__make_element_class__(MyElementB) 2) then you can use these classes (and will benefit from the category stuff) Parent P: def _element_constructor_(self, data): if some_condition(data): return self.element_class_A(data) else: return self.element_class_B(data) 3) In order to make the tests pass (ie TestSuite(P).run()) you must set P.element to either element_class_A or element_class_B. Vincent 2014-08-23 10:53 UTC+02:00, Daniel Krenn <kr...@aon.at>: > I'm going through [1] to construct a new algebraic structure. I have one > parent, but want more than one elements, which should be associated to > this parent. More precisely, I have the following classes: > > +- MyElementBase > +-- MyElementA (derived from MyElementBase) > +-- MyElementB (derived from MyElementBase) > > In [1] it says, we should use > return self.element_class(data) > in Parent._element_constructor_ to create objects. This creates a class > derived from Parent.Element (which IMHO should be MyElementBase) and > Parent.category().element_class. > > How can I create "the correct" instance of MyElementA and MyElementB > inside _element_constructor_ depending on the input? (I want to do this, > since MyElementA is a specialized version of MyElementBase for some > inputs; similar MyElementB) > > Daniel > > [1] > http://www.sagemath.org/doc/thematic_tutorials/coercion_and_categories.html > > -- > 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 http://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. > -- 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 http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.