With this code (follow up of https://groups.google.com/forum/#!topic/sage-devel/4uxI1XVtoDs): from sage.matrix.matrix_mod2_dense import Matrix_mod2_dense from sage.matrix.matrix_gf2e_dense import Matrix_gf2e_dense
class LinearLayerGeneric: def _repr_(self): return "LinearLayer of dimension %d x %d represented by\n%s" \ % (self.dimensions() + (self.parent(self),)) def LinearLayer(L): parent = L.parent() return type("LinearLayerGF2", (LinearLayerGeneric, Matrix_mod2_dense), {})(parent, L) ll = LinearLayer(matrix(GF(2), 2, 2, [1, 0, 0, 1])) I would expect to see sage: ll LinearLayer of dimension 2 x 2 represented by [1 0] [0 1] But what I instead get, is this sage: ascii_art(ll, " vs ", ll._repr_()) LinearLayer of dimension 2 x 2 represented by [1 0] [1 0] [0 1] vs [0 1] So why is the _repr_() method from the matrix class called and not from LinearLayerGeneric? The LinearLayer class is also listed first in the __mro__: sage: ll.__class__.__mro__ (<class '__main__.LinearLayerGF2'>, <class __main__.LinearLayerGeneric at 0x7f4ab67e46d0>, <type 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>, <type 'sage.matrix.matrix_dense.Matrix_dense'>, <type 'sage.matrix.matrix2.Matrix'>, <type 'sage.matrix.matrix1.Matrix'>, <type 'sage.matrix.matrix0.Matrix'>, <type 'sage.structure.element.Matrix'>, <type 'sage.structure.element.ModuleElement'>, <type 'sage.structure.element.Element'>, <type 'sage.structure.sage_object.SageObject'>, <type 'object'>) -- 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.