Skip to content

Commit

Permalink
gh-36550: remove deprecated name parameter in category ; capital for …
Browse files Browse the repository at this point in the history
…Coxeter

    
This is removing a deprecated parameter "name" in the init of
"Category".

Also using the opportunity to add the capital to the name of  Coxeter.

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation accordingly.
    
URL: #36550
Reported by: Frédéric Chapoton
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Oct 29, 2023
2 parents 5c6004b + 092186f commit ccb0934
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 102 deletions.
16 changes: 9 additions & 7 deletions src/sage/categories/bimodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,24 @@ class Bimodules(CategoryWithParameters):

def __init__(self, left_base, right_base, name=None):
"""
The ``name`` parameter is ignored.
EXAMPLES::
sage: C = Bimodules(QQ, ZZ)
sage: TestSuite(C).run()
"""
if not ( left_base in Rings() or
(isinstance(left_base, Category)
and left_base.is_subcategory(Rings())) ):
if not (left_base in Rings() or
(isinstance(left_base, Category)
and left_base.is_subcategory(Rings()))):
raise ValueError("the left base must be a ring or a subcategory of Rings()")
if not ( right_base in Rings() or
(isinstance(right_base, Category)
and right_base.is_subcategory(Rings())) ):
if not (right_base in Rings() or
(isinstance(right_base, Category)
and right_base.is_subcategory(Rings()))):
raise ValueError("the right base must be a ring or a subcategory of Rings()")
self._left_base_ring = left_base
self._right_base_ring = right_base
Category.__init__(self, name)
Category.__init__(self)

def _make_named_class_key(self, name):
r"""
Expand Down
102 changes: 43 additions & 59 deletions src/sage/categories/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@

_join_cache = WeakValueDictionary()


class Category(UniqueRepresentation, SageObject):
r"""
The base class for modeling mathematical categories, like for example:
Expand Down Expand Up @@ -448,7 +449,7 @@ class of ``C`` is a dynamic subclass ``Cs_with_category`` of
cls = cls.__base__
return super().__classcall__(cls, *args, **options)

def __init__(self, s=None):
def __init__(self):
"""
Initialize this category.
Expand All @@ -468,12 +469,10 @@ def __init__(self, s=None):
.. NOTE::
Specifying the name of this category by passing a string
is deprecated. If the default name (built from the name of
the class) is not adequate, please use
If the default name of the category (built from the name of
the class) is not adequate, please implement
:meth:`_repr_object_names` to customize it.
"""
assert s is None
self.__class__ = dynamic_class("{}_with_category".format(self.__class__.__name__),
(self.__class__, self.subcategory_class, ),
cache=False, reduction=None,
Expand All @@ -491,49 +490,38 @@ def _label(self):
"""
t = str(self.__class__.__base__)
t = t[t.rfind('.')+1:]
t = t[t.rfind('.') + 1:]
return t[:t.rfind("'")]

# TODO: move this code into the method _repr_object_names once passing a string is not accepted anymore
@lazy_attribute
def __repr_object_names(self):
def _repr_object_names(self):
"""
Determine the name of the objects of this category
from its type, if it has not been explicitly given
at initialisation.
Return the name of the objects of this category.
EXAMPLES::
sage: Rings()._Category__repr_object_names
'rings'
sage: PrincipalIdealDomains()._Category__repr_object_names
'principal ideal domains'
sage: FiniteGroups()._repr_object_names()
'finite groups'
sage: AlgebrasWithBasis(QQ)._repr_object_names()
'algebras with basis over Rational Field'
TESTS::
sage: Rings()
Category of rings
sage: Rings()._repr_object_names()
'rings'
sage: PrincipalIdealDomains()._repr_object_names()
'principal ideal domains'
"""
i = -1
s = self._label
while i < len(s)-1:
while i < len(s) - 1:
for i in range(len(s)):
if s[i].isupper():
s = s[:i] + " " + s[i].lower() + s[i+1:]
s = s[:i] + " " + s[i].lower() + s[i + 1:]
break
return s.lstrip()

def _repr_object_names(self):
"""
Return the name of the objects of this category.
EXAMPLES::
sage: FiniteGroups()._repr_object_names()
'finite groups'
sage: AlgebrasWithBasis(QQ)._repr_object_names()
'algebras with basis over Rational Field'
"""
return self.__repr_object_names

def _short_name(self):
"""
Return a CamelCase name for this category.
Expand Down Expand Up @@ -1256,7 +1244,7 @@ def structure(self):
recursively from the result of :meth:`additional_structure`
on the super categories of ``self``.
"""
result = { D for C in self.super_categories() for D in C.structure() }
result = {D for C in self.super_categories() for D in C.structure()}
if self.additional_structure() is not None:
result.add(self)
return frozenset(result)
Expand Down Expand Up @@ -1319,8 +1307,7 @@ def is_full_subcategory(self, other):
False
"""
return self.is_subcategory(other) and \
len(self.structure()) == \
len(other.structure())
len(self.structure()) == len(other.structure())

@cached_method
def full_super_categories(self):
Expand Down Expand Up @@ -1446,27 +1433,26 @@ def _test_category(self, **options):
Traceback (most recent call last):
...
AssertionError: Category of my objects is not a subcategory of Objects()
"""
from sage.categories.objects import Objects
from sage.categories.objects import Objects
from sage.categories.sets_cat import Sets
tester = self._tester(**options)
tester.assertTrue(isinstance(self.super_categories(), list),
"%s.super_categories() should return a list" % self)
"%s.super_categories() should return a list" % self)
tester.assertTrue(self.is_subcategory(Objects()),
"%s is not a subcategory of Objects()" % self)
"%s is not a subcategory of Objects()" % self)
tester.assertTrue(isinstance(self.parent_class, type))
tester.assertTrue(all(not isinstance(cat, JoinCategory) for cat in self._super_categories))
if not isinstance(self, JoinCategory):
tester.assertTrue(all(self._cmp_key > cat._cmp_key for cat in self._super_categories))
tester.assertTrue(self.is_subcategory( Category.join(self.super_categories()) )) # Not an obviously passing test with axioms
tester.assertTrue(all(self._cmp_key > cat._cmp_key for cat in self._super_categories))
tester.assertTrue(self.is_subcategory(Category.join(self.super_categories()))) # Not an obviously passing test with axioms

for category in self._all_super_categories_proper:
if self.is_full_subcategory(category):
tester.assertTrue(any(cat.is_subcategory(category)
for cat in self.full_super_categories()),
"Every full super category should be a super category"
"of some immediate full super category")
for cat in self.full_super_categories()),
"Every full super category should be a super category"
"of some immediate full super category")

if self.is_subcategory(Sets()):
tester.assertTrue(isinstance(self.parent_class, type))
Expand Down Expand Up @@ -1588,7 +1574,7 @@ def _make_named_class(self, name, method_provider, cache=False, picklable=True):
doccls = cls
else:
# Otherwise, check XXXMethods
assert inspect.isclass(method_provider_cls),\
assert inspect.isclass(method_provider_cls), \
"%s.%s should be a class" % (cls.__name__, method_provider)
mro = inspect.getmro(method_provider_cls)
if len(mro) > 2 or (len(mro) == 2 and mro[1] is not object):
Expand Down Expand Up @@ -1941,7 +1927,7 @@ def _meet_(self, other):
appropriate convention for A<B. Using subcategory calls
for A<B, but the current meet and join call for A>B.
"""
if self is other: # useful? fast pathway
if self is other: # useful? fast pathway
return self
elif self.is_subcategory(other):
return other
Expand Down Expand Up @@ -2050,14 +2036,13 @@ def _with_axiom_as_tuple(self, axiom):
return (axiom_attribute(self),)
warn(("Expecting {}.{} to be a subclass of CategoryWithAxiom to"
" implement a category with axiom; got {}; ignoring").format(
self.__class__.__base__.__name__, axiom, axiom_attribute))
self.__class__.__base__.__name__, axiom, axiom_attribute))

# self does not implement this axiom
result = (self, ) + \
tuple(cat
for category in self._super_categories
for cat in category._with_axiom_as_tuple(axiom))
hook = getattr(self, axiom+"_extra_super_categories", None)
result = (self, ) + tuple(cat
for category in self._super_categories
for cat in category._with_axiom_as_tuple(axiom))
hook = getattr(self, axiom + "_extra_super_categories", None)
if hook is not None:
assert inspect.ismethod(hook)
result += tuple(hook())
Expand Down Expand Up @@ -2593,6 +2578,7 @@ def is_Category(x):
"""
return isinstance(x, Category)


@cached_function
def category_sample():
r"""
Expand All @@ -2606,7 +2592,8 @@ def category_sample():
sage: from sage.categories.category import category_sample
sage: sorted(category_sample(), key=str) # needs sage.groups
[Category of G-sets for Symmetric group of order 8! as a permutation group,
[Category of Coxeter groups,
Category of G-sets for Symmetric group of order 8! as a permutation group,
Category of Hecke modules over Rational Field,
Category of Lie algebras over Rational Field,
Category of additive magmas, ...,
Expand Down Expand Up @@ -2900,6 +2887,7 @@ def _subcategory_hook_(self, C):
return False
return Unknown


#############################################################
# Join of several categories
#############################################################
Expand Down Expand Up @@ -2948,29 +2936,25 @@ def __init__(self, super_categories, **kwds):
INPUT:
- super_categories -- Categories to join. This category will
- ``super_categories`` -- Categories to join. This category will
consist of objects and morphisms that lie in all of these
categories.
- name -- An optional name for this category.
- ``name`` -- ignored
TESTS::
sage: from sage.categories.category import JoinCategory
sage: C = JoinCategory((Groups(), CommutativeAdditiveMonoids())); C
Join of Category of groups and Category of commutative additive monoids
sage: TestSuite(C).run()
"""
assert len(super_categories) >= 2
assert all(not isinstance(category, JoinCategory) for category in super_categories)
# Use __super_categories to not overwrite the lazy attribute Category._super_categories
# Maybe this would not be needed if the flattening/sorting is does consistently?
self.__super_categories = list(super_categories)
if 'name' in kwds:
Category.__init__(self, kwds['name'])
else:
Category.__init__(self)
Category.__init__(self)

def _make_named_class_key(self, name):
r"""
Expand Down
8 changes: 6 additions & 2 deletions src/sage/categories/category_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def __init__(self, base, name=None):
r"""
Initialize ``self``.
The ``name`` parameter is ignored.
EXAMPLES::
sage: S = Spec(ZZ)
Expand All @@ -182,7 +184,7 @@ def __init__(self, base, name=None):
sage: TestSuite(C).run()
"""
self.__base = base
Category.__init__(self, name)
Category.__init__(self)

def _test_category_over_bases(self, **options):
"""
Expand Down Expand Up @@ -527,13 +529,15 @@ def __init__(self, ambient, name=None):
"""
Initialize ``self``.
The parameter ``name`` is ignored.
EXAMPLES::
sage: C = Ideals(IntegerRing())
sage: TestSuite(C).run()
"""
self.__ambient = ambient
Category.__init__(self, name)
Category.__init__(self)

def ambient(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/category_with_axiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class from the base category class::
covers the following examples::
sage: FiniteCoxeterGroups()
Category of finite coxeter groups
Category of finite Coxeter groups
sage: FiniteCoxeterGroups() is CoxeterGroups().Finite()
True
sage: FiniteCoxeterGroups._base_category_class_and_axiom_origin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def Irreducible(self):
sage: ComplexReflectionGroups().Irreducible()
Category of irreducible complex reflection groups
sage: CoxeterGroups().Irreducible()
Category of irreducible coxeter groups
Category of irreducible Coxeter groups
TESTS::
Expand Down
13 changes: 12 additions & 1 deletion src/sage/categories/coxeter_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CoxeterGroups(Category_singleton):
EXAMPLES::
sage: C = CoxeterGroups(); C
Category of coxeter groups
Category of Coxeter groups
sage: C.super_categories()
[Category of generalized coxeter groups]
Expand Down Expand Up @@ -128,6 +128,17 @@ def additional_structure(self):
Finite = LazyImport('sage.categories.finite_coxeter_groups', 'FiniteCoxeterGroups')
Algebras = LazyImport('sage.categories.coxeter_group_algebras', 'CoxeterGroupAlgebras')

def _repr_object_names(self):
"""
Return the name of the objects of this category.
EXAMPLES::
sage: CoxeterGroups().Finite()
Category of finite Coxeter groups
"""
return "Coxeter groups"

class ParentMethods:
@abstract_method
def coxeter_matrix(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/finite_complex_reflection_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def WellGenerated(self):
desired output (well generated does not appear)::
sage: CoxeterGroups().Finite()
Category of finite coxeter groups
Category of finite Coxeter groups
"""
return self._with_axiom('WellGenerated')

Expand Down
Loading

0 comments on commit ccb0934

Please sign in to comment.