#7921: Categories for extension types via __getattr___
-------------------------------------+---------------------------------
       Reporter:  nthiery            |        Owner:  nthiery
           Type:  enhancement        |       Status:  closed
       Priority:  major              |    Milestone:  sage-4.3.2
      Component:  categories         |   Resolution:  fixed
       Keywords:                     |    Merged in:  sage-4.3.2.alpha0
        Authors:  Nicolas M. ThiƩry  |    Reviewers:  Robert Bradshaw
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
   Dependencies:                     |     Stopgaps:
-------------------------------------+---------------------------------

Comment (by nthiery):

 Replying to [comment:15 saraedum]:
 > I have a question regarding this old ticket. The following fails:
 > {{{
 > sage: a = ModularForms(11,4).an_element()
 > sage: a._test_category()
 > }}}
 > The reason for this is that `a` is not an extension class so
 `_test_category` expects that the type of `a` inherits from
 `a.parent().category().element_class`. Now if I try to do such inheritance
 > {{{
 > class HeckeModuleElement(sage.modules.module_element.ModuleElement,
 HeckeModules.element_class):
 > }}}
 > I get a
 > {{{
 > metaclass conflict: the metaclass of a derived class must be a (non-
 strict) subclass of the metaclasses of all its base
 > }}}

 If it's not an extension type, it really should inherit
 `a.parent().category().element_class`.
 Except in complicated cases (e.g. parents whose elements can belong to
 several classes), this is taken care of automatically if a category is
 specified to
 `Parent.__init__`; otherwise one needs to use manually
 `_make_element_class`. See sage.categories.primer (better with #10963
 applied) and the
 documentation of Category for details.

 Most likely the issue here is that the category is not specified
 properly.

 > Anyway, I'm getting the feeling that such inheritance does not happen
 anywhere (partly because most element classes are extension classes).

 Most of my bread and butter element classes are *not* extension
 classes :-) Just for one example:

 {{{
 sage: x = CombinatorialFreeModule(QQ, [1,2,3]).an_element()
 sage: x.__class__
 <class
 
'sage.combinat.free_module.CombinatorialFreeModule_with_category.element_class'>
 sage: x.__class__.__bases__
 (sage.combinat.free_module.CombinatorialFreeModuleElement,
  sage.categories.vector_spaces.VectorSpaces.WithBasis.element_class)
 }}}

 > So is it safe to remove this check from `_test_category`?

 Please don't: so far failures here have always pointed to actual bugs.

 Cheers,
                             Nicolas

--
Ticket URL: <http://trac.sagemath.org/ticket/7921#comment:16>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to