# HG changeset patch
# User Simon King
# 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/sage/categories/category.py
+++ b/sage/categories/category.py
@@ -56,7 +56,7 @@
from sage.structure.sage_object import SageObject
from sage.structure.unique_representation import UniqueRepresentation
-from sage.structure.dynamic_class import dynamic_class_internal
+from sage.structure.dynamic_class import dynamic_class
@cached_function
def _join(categories, as_list):
@@ -704,25 +704,22 @@
sage: type(C)
+
+ By trac ticket #11935, a parent class only depends on the base ring
+ of a category if the choice of the base ring alters the type of the
+ super categories. A typical example is the category of algebras over
+ a field versus algebras over a non-field.
+ ::
+
+ sage: Algebras(QQ).parent_class is Algebras(GF(3)).parent_class
+ True
+ sage: Algebras(QQ).parent_class is Algebras(ZZ).parent_class
+ False
+
"""
- # Remark:
- # For now, we directly call the underlying function, avoiding the overhead
- # of using a cached function. The rationale: When this lazy method is called
- # then we can be sure that the parent class had not been constructed before.
- # The parent and element classes belong to a category, and they are pickled
- # as such. Hence, they are rightfully cached as an attribute of a category.
- #
- # However, we should try to "unify" parent classes. They should depend on the
- # super categories, but not on the base (except when the super categories depend
- # on the base). When that is done, calling the cached function will be needed again.
- #return dynamic_class("%s.parent_class"%self.__class__.__name__,
- # tuple(cat.parent_class for cat in self.super_categories()),
- # self.ParentMethods,
- # reduction = (getattr, (self, "parent_class")))
- return dynamic_class_internal.f("%s.parent_class"%self.__class__.__name__,
+ return dynamic_class("%s.parent_class"%self.__class__.__name__,
tuple(cat.parent_class for cat in self.super_categories()),
- self.ParentMethods,
- reduction = (getattr, (self, "parent_class")))
+ self.ParentMethods)
@lazy_attribute
def element_class(self):
@@ -735,26 +732,22 @@
sage: type(C)
+
+ By trac ticket #11935, an element class only depends on the base ring
+ of a category if the choice of the base ring alters the type of the
+ super categories. A typical example is the category of algebras over
+ a field versus algebras over a non-field.
+ ::
+
+ sage: Algebras(QQ).element_class is Algebras(GF(3)).element_class
+ True
+ sage: Algebras(QQ).element_class is Algebras(ZZ).element_class
+ False
+
"""
- # Remark:
- # For now, we directly call the underlying function, avoiding the overhead
- # of using a cached function. The rationale: When this lazy method is called
- # then we can be sure that the element class had not been constructed before.
- # The parent and element classes belong to a category, and they are pickled
- # as such. Hence, they are rightfully cached as an attribute of a category.
- #
- # However, we should try to "unify" element classes. They should depend on the
- # super categories, but not on the base (except when the super categories depend
- # on the base). When that is done, calling the cached function will be needed again.
- #return dynamic_class("%s.element_class"%self.__class__.__name__,
- # (cat.element_class for cat in self.super_categories()),
- # self.ElementMethods,
- # reduction = (getattr, (self, "element_class"))
- # )
- return dynamic_class_internal.f("%s.element_class"%self.__class__.__name__,
+ return dynamic_class("%s.element_class"%self.__class__.__name__,
tuple(cat.element_class for cat in self.super_categories()),
- self.ElementMethods,
- reduction = (getattr, (self, "element_class")))
+ self.ElementMethods)
def required_methods(self):
"""