Elements are supposed to inherit from their category's element_class, but this requirement is waived for elements that are implemented in Cython. See the following snippet from sage.structure.element.Element._test_category (line 495 of element.pyx):
# Tests that self inherits methods from the categories if not is_extension_type(self.__class__): # For usual Python classes, that should be done with # standard inheritance tester.assert_(isinstance(self, self.parent().category().element_class)) else: # For extension types we just check that inheritance # occurs on a dummy attribute of Sets().ElementMethods tester.assert_(hasattr(self, "_dummy_attribute")) Unfortunately, whenever I write a Python class I've also been very frustrated trying to get the class I'm writing to inherit from the appropriate element_class. As a consequence I try to write most of my elements in Cython. :-) The inheritance is set up to work correctly if you follow the paradigm of just defining an ElementMethods class on the category (see basically any category in Sage) and throwing methods into it. You could just inherit from Rings().element_class (for example), but this doesn't work very well if you want to use one element class for elements of parents in different categories (e.g. Z/NZ for both prime and composite N). Frankly, this is one of my biggest frustrations with the current category framework. But maybe I'm just missing something. :-) David On Fri, Mar 23, 2012 at 19:15, AlexGhitza <aghi...@gmail.com> wrote: > Hello sage-devel, > > (I sent this from my email a couple of hours ago but it hasn't appeared > on the list yet. I am trying again from within Google Groups. > Apologies if it ends up being a duplicate post.) > > > Schemes and their points are not yet properly embedded in the category > framework. One of the trac tickets listing the issues is > > http://trac.sagemath.org/sage_**trac/ticket/7946<http://trac.sagemath.org/sage_trac/ticket/7946> > > which mentions that Volker Braun had resolved some of the issues but > some related to elements still remain. > > Here is what seems to be the root of the problem: > > sage: A = AffineSpace(2, ZZ) > sage: p = A(0, 0) > sage: p.parent().category().element_**class > <class 'sage.categories.category.**Schemes_abstract.HomCategory.** > element_class'> > sage: type(p) > <class 'sage.schemes.generic.**morphism.SchemeMorphism_point_**affine'> > > Compare this with > > sage: type(QQ(0)) > <type 'sage.rings.rational.Rational'**> > sage: QQ(0).parent().category().**element_class > <class 'sage.categories.quotient_**fields.QuotientFields.element_**class'> > > In the latter case (elements of QQ), things are set up so that Sage > knows that Rational is a subtype of QuotientFields.element_class. But > for schemes, Sage does not know that SchemeMorphism_point_affine is a > subtype of Schemes_abstract.HomCategory.**element_class. So how do I fix > this? I have tried to locate how this is done for QQ, but I haven't > succeeded. Can anyone point me to this? > > -- > Best, > Alex > > Alex Ghitza -- http://aghitza.org/ > Lecturer in Mathematics -- The University of Melbourne -- Australia > > -- > To post to this group, send an email to sage-devel@googlegroups.com > To unsubscribe from this group, send an email to > sage-devel+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-devel > URL: http://www.sagemath.org > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org