# HG changeset patch
# User Simon King <simon.king@unijena.de>
# Date 1318939905 7200
# Node ID 7edc18640d1f7099df84cb0f6b9b61a8a3b8a6f9
# Parent 5a230a7dc86c584e7faf3a5c9665ee6a7547342a
#11935: Make the parent/element classes of categories as independent as possible from the base ring.
diff git a/sage/categories/category.py b/sage/categories/category.py
a

b


56  56  
57  57  from sage.structure.sage_object import SageObject 
58  58  from sage.structure.unique_representation import UniqueRepresentation 
59   from sage.structure.dynamic_class import dynamic_class_internal 
 59  from sage.structure.dynamic_class import dynamic_class 
60  60  
61  61  @cached_function 
62  62  def _join(categories, as_list): 
… 
… 

704  704  <class 'sage.categories.algebras.Algebras.parent_class'> 
705  705  sage: type(C) 
706  706  <class 'sage.structure.dynamic_class.DynamicMetaclass'> 
 707  
 708  By trac ticket #11935, a parent class only depends on the base ring 
 709  of a category if the choice of the base ring alters the type of the 
 710  super categories. A typical example is the category of algebras over 
 711  a field versus algebras over a nonfield. 
 712  :: 
 713  
 714  sage: Algebras(QQ).parent_class is Algebras(GF(3)).parent_class 
 715  True 
 716  sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class 
 717  False 
 718  
707  719  """ 
708   # Remark: 
709   # For now, we directly call the underlying function, avoiding the overhead 
710   # of using a cached function. The rationale: When this lazy method is called 
711   # then we can be sure that the parent class had not been constructed before. 
712   # The parent and element classes belong to a category, and they are pickled 
713   # as such. Hence, they are rightfully cached as an attribute of a category. 
714   # 
715   # However, we should try to "unify" parent classes. They should depend on the 
716   # super categories, but not on the base (except when the super categories depend 
717   # on the base). When that is done, calling the cached function will be needed again. 
718   #return dynamic_class("%s.parent_class"%self.__class__.__name__, 
719   # tuple(cat.parent_class for cat in self.super_categories()), 
720   # self.ParentMethods, 
721   # reduction = (getattr, (self, "parent_class"))) 
722   return dynamic_class_internal.f("%s.parent_class"%self.__class__.__name__, 
 720  return dynamic_class("%s.parent_class"%self.__class__.__name__, 
723  721  tuple(cat.parent_class for cat in self.super_categories()), 
724   self.ParentMethods, 
725   reduction = (getattr, (self, "parent_class"))) 
 722  self.ParentMethods) 
726  723  
727  724  @lazy_attribute 
728  725  def element_class(self): 
… 
… 

735  732  <class 'sage.categories.algebras.Algebras.element_class'> 
736  733  sage: type(C) 
737  734  <class 'sage.structure.dynamic_class.DynamicMetaclass'> 
 735  
 736  By trac ticket #11935, an element class only depends on the base ring 
 737  of a category if the choice of the base ring alters the type of the 
 738  super categories. A typical example is the category of algebras over 
 739  a field versus algebras over a nonfield. 
 740  :: 
 741  
 742  sage: Algebras(QQ).element_class is Algebras(GF(3)).element_class 
 743  True 
 744  sage: Algebras(QQ).element_class is Algebras(ZZ).element_class 
 745  False 
 746  
738  747  """ 
739   # Remark: 
740   # For now, we directly call the underlying function, avoiding the overhead 
741   # of using a cached function. The rationale: When this lazy method is called 
742   # then we can be sure that the element class had not been constructed before. 
743   # The parent and element classes belong to a category, and they are pickled 
744   # as such. Hence, they are rightfully cached as an attribute of a category. 
745   # 
746   # However, we should try to "unify" element classes. They should depend on the 
747   # super categories, but not on the base (except when the super categories depend 
748   # on the base). When that is done, calling the cached function will be needed again. 
749   #return dynamic_class("%s.element_class"%self.__class__.__name__, 
750   # (cat.element_class for cat in self.super_categories()), 
751   # self.ElementMethods, 
752   # reduction = (getattr, (self, "element_class")) 
753   # ) 
754   return dynamic_class_internal.f("%s.element_class"%self.__class__.__name__, 
 748  return dynamic_class("%s.element_class"%self.__class__.__name__, 
755  749  tuple(cat.element_class for cat in self.super_categories()), 
756   self.ElementMethods, 
757   reduction = (getattr, (self, "element_class"))) 
 750  self.ElementMethods) 
758  751  
759  752  def required_methods(self): 
760  753  """ 