118
118
119
119
_join_cache = WeakValueDictionary ()
120
120
121
+
121
122
class Category (UniqueRepresentation , SageObject ):
122
123
r"""
123
124
The base class for modeling mathematical categories, like for example:
@@ -448,7 +449,7 @@ class of ``C`` is a dynamic subclass ``Cs_with_category`` of
448
449
cls = cls .__base__
449
450
return super ().__classcall__ (cls , * args , ** options )
450
451
451
- def __init__ (self , s = None ):
452
+ def __init__ (self ):
452
453
"""
453
454
Initialize this category.
454
455
@@ -468,12 +469,10 @@ def __init__(self, s=None):
468
469
469
470
.. NOTE::
470
471
471
- Specifying the name of this category by passing a string
472
- is deprecated. If the default name (built from the name of
473
- the class) is not adequate, please use
472
+ If the default name of the category (built from the name of
473
+ the class) is not adequate, please implement
474
474
:meth:`_repr_object_names` to customize it.
475
475
"""
476
- assert s is None
477
476
self .__class__ = dynamic_class ("{}_with_category" .format (self .__class__ .__name__ ),
478
477
(self .__class__ , self .subcategory_class , ),
479
478
cache = False , reduction = None ,
@@ -491,49 +490,38 @@ def _label(self):
491
490
492
491
"""
493
492
t = str (self .__class__ .__base__ )
494
- t = t [t .rfind ('.' )+ 1 :]
493
+ t = t [t .rfind ('.' ) + 1 :]
495
494
return t [:t .rfind ("'" )]
496
495
497
- # TODO: move this code into the method _repr_object_names once passing a string is not accepted anymore
498
- @lazy_attribute
499
- def __repr_object_names (self ):
496
+ def _repr_object_names (self ):
500
497
"""
501
- Determine the name of the objects of this category
502
- from its type, if it has not been explicitly given
503
- at initialisation.
498
+ Return the name of the objects of this category.
504
499
505
500
EXAMPLES::
506
501
507
- sage: Rings()._Category__repr_object_names
508
- 'rings'
509
- sage: PrincipalIdealDomains()._Category__repr_object_names
510
- 'principal ideal domains'
502
+ sage: FiniteGroups()._repr_object_names()
503
+ 'finite groups'
504
+ sage: AlgebrasWithBasis(QQ)._repr_object_names()
505
+ 'algebras with basis over Rational Field'
506
+
507
+ TESTS::
511
508
512
509
sage: Rings()
513
510
Category of rings
511
+ sage: Rings()._repr_object_names()
512
+ 'rings'
513
+ sage: PrincipalIdealDomains()._repr_object_names()
514
+ 'principal ideal domains'
514
515
"""
515
516
i = - 1
516
517
s = self ._label
517
- while i < len (s )- 1 :
518
+ while i < len (s ) - 1 :
518
519
for i in range (len (s )):
519
520
if s [i ].isupper ():
520
- s = s [:i ] + " " + s [i ].lower () + s [i + 1 :]
521
+ s = s [:i ] + " " + s [i ].lower () + s [i + 1 :]
521
522
break
522
523
return s .lstrip ()
523
524
524
- def _repr_object_names (self ):
525
- """
526
- Return the name of the objects of this category.
527
-
528
- EXAMPLES::
529
-
530
- sage: FiniteGroups()._repr_object_names()
531
- 'finite groups'
532
- sage: AlgebrasWithBasis(QQ)._repr_object_names()
533
- 'algebras with basis over Rational Field'
534
- """
535
- return self .__repr_object_names
536
-
537
525
def _short_name (self ):
538
526
"""
539
527
Return a CamelCase name for this category.
@@ -1256,7 +1244,7 @@ def structure(self):
1256
1244
recursively from the result of :meth:`additional_structure`
1257
1245
on the super categories of ``self``.
1258
1246
"""
1259
- result = { D for C in self .super_categories () for D in C .structure () }
1247
+ result = {D for C in self .super_categories () for D in C .structure ()}
1260
1248
if self .additional_structure () is not None :
1261
1249
result .add (self )
1262
1250
return frozenset (result )
@@ -1319,8 +1307,7 @@ def is_full_subcategory(self, other):
1319
1307
False
1320
1308
"""
1321
1309
return self .is_subcategory (other ) and \
1322
- len (self .structure ()) == \
1323
- len (other .structure ())
1310
+ len (self .structure ()) == len (other .structure ())
1324
1311
1325
1312
@cached_method
1326
1313
def full_super_categories (self ):
@@ -1446,27 +1433,26 @@ def _test_category(self, **options):
1446
1433
Traceback (most recent call last):
1447
1434
...
1448
1435
AssertionError: Category of my objects is not a subcategory of Objects()
1449
-
1450
1436
"""
1451
- from sage .categories .objects import Objects
1437
+ from sage .categories .objects import Objects
1452
1438
from sage .categories .sets_cat import Sets
1453
1439
tester = self ._tester (** options )
1454
1440
tester .assertTrue (isinstance (self .super_categories (), list ),
1455
- "%s.super_categories() should return a list" % self )
1441
+ "%s.super_categories() should return a list" % self )
1456
1442
tester .assertTrue (self .is_subcategory (Objects ()),
1457
- "%s is not a subcategory of Objects()" % self )
1443
+ "%s is not a subcategory of Objects()" % self )
1458
1444
tester .assertTrue (isinstance (self .parent_class , type ))
1459
1445
tester .assertTrue (all (not isinstance (cat , JoinCategory ) for cat in self ._super_categories ))
1460
1446
if not isinstance (self , JoinCategory ):
1461
- tester .assertTrue (all (self ._cmp_key > cat ._cmp_key for cat in self ._super_categories ))
1462
- tester .assertTrue (self .is_subcategory ( Category .join (self .super_categories ()) )) # Not an obviously passing test with axioms
1447
+ tester .assertTrue (all (self ._cmp_key > cat ._cmp_key for cat in self ._super_categories ))
1448
+ tester .assertTrue (self .is_subcategory (Category .join (self .super_categories ()))) # Not an obviously passing test with axioms
1463
1449
1464
1450
for category in self ._all_super_categories_proper :
1465
1451
if self .is_full_subcategory (category ):
1466
1452
tester .assertTrue (any (cat .is_subcategory (category )
1467
- for cat in self .full_super_categories ()),
1468
- "Every full super category should be a super category"
1469
- "of some immediate full super category" )
1453
+ for cat in self .full_super_categories ()),
1454
+ "Every full super category should be a super category"
1455
+ "of some immediate full super category" )
1470
1456
1471
1457
if self .is_subcategory (Sets ()):
1472
1458
tester .assertTrue (isinstance (self .parent_class , type ))
@@ -1588,7 +1574,7 @@ def _make_named_class(self, name, method_provider, cache=False, picklable=True):
1588
1574
doccls = cls
1589
1575
else :
1590
1576
# Otherwise, check XXXMethods
1591
- assert inspect .isclass (method_provider_cls ),\
1577
+ assert inspect .isclass (method_provider_cls ), \
1592
1578
"%s.%s should be a class" % (cls .__name__ , method_provider )
1593
1579
mro = inspect .getmro (method_provider_cls )
1594
1580
if len (mro ) > 2 or (len (mro ) == 2 and mro [1 ] is not object ):
@@ -1941,7 +1927,7 @@ def _meet_(self, other):
1941
1927
appropriate convention for A<B. Using subcategory calls
1942
1928
for A<B, but the current meet and join call for A>B.
1943
1929
"""
1944
- if self is other : # useful? fast pathway
1930
+ if self is other : # useful? fast pathway
1945
1931
return self
1946
1932
elif self .is_subcategory (other ):
1947
1933
return other
@@ -2050,14 +2036,13 @@ def _with_axiom_as_tuple(self, axiom):
2050
2036
return (axiom_attribute (self ),)
2051
2037
warn (("Expecting {}.{} to be a subclass of CategoryWithAxiom to"
2052
2038
" implement a category with axiom; got {}; ignoring" ).format (
2053
- self .__class__ .__base__ .__name__ , axiom , axiom_attribute ))
2039
+ self .__class__ .__base__ .__name__ , axiom , axiom_attribute ))
2054
2040
2055
2041
# self does not implement this axiom
2056
- result = (self , ) + \
2057
- tuple (cat
2058
- for category in self ._super_categories
2059
- for cat in category ._with_axiom_as_tuple (axiom ))
2060
- hook = getattr (self , axiom + "_extra_super_categories" , None )
2042
+ result = (self , ) + tuple (cat
2043
+ for category in self ._super_categories
2044
+ for cat in category ._with_axiom_as_tuple (axiom ))
2045
+ hook = getattr (self , axiom + "_extra_super_categories" , None )
2061
2046
if hook is not None :
2062
2047
assert inspect .ismethod (hook )
2063
2048
result += tuple (hook ())
@@ -2593,6 +2578,7 @@ def is_Category(x):
2593
2578
"""
2594
2579
return isinstance (x , Category )
2595
2580
2581
+
2596
2582
@cached_function
2597
2583
def category_sample ():
2598
2584
r"""
@@ -2606,7 +2592,8 @@ def category_sample():
2606
2592
2607
2593
sage: from sage.categories.category import category_sample
2608
2594
sage: sorted(category_sample(), key=str) # needs sage.groups
2609
- [Category of G-sets for Symmetric group of order 8! as a permutation group,
2595
+ [Category of Coxeter groups,
2596
+ Category of G-sets for Symmetric group of order 8! as a permutation group,
2610
2597
Category of Hecke modules over Rational Field,
2611
2598
Category of Lie algebras over Rational Field,
2612
2599
Category of additive magmas, ...,
@@ -2900,6 +2887,7 @@ def _subcategory_hook_(self, C):
2900
2887
return False
2901
2888
return Unknown
2902
2889
2890
+
2903
2891
#############################################################
2904
2892
# Join of several categories
2905
2893
#############################################################
@@ -2948,29 +2936,25 @@ def __init__(self, super_categories, **kwds):
2948
2936
2949
2937
INPUT:
2950
2938
2951
- - super_categories -- Categories to join. This category will
2939
+ - `` super_categories`` -- Categories to join. This category will
2952
2940
consist of objects and morphisms that lie in all of these
2953
2941
categories.
2954
2942
2955
- - name -- An optional name for this category.
2943
+ - `` name`` -- ignored
2956
2944
2957
2945
TESTS::
2958
2946
2959
2947
sage: from sage.categories.category import JoinCategory
2960
2948
sage: C = JoinCategory((Groups(), CommutativeAdditiveMonoids())); C
2961
2949
Join of Category of groups and Category of commutative additive monoids
2962
2950
sage: TestSuite(C).run()
2963
-
2964
2951
"""
2965
2952
assert len (super_categories ) >= 2
2966
2953
assert all (not isinstance (category , JoinCategory ) for category in super_categories )
2967
2954
# Use __super_categories to not overwrite the lazy attribute Category._super_categories
2968
2955
# Maybe this would not be needed if the flattening/sorting is does consistently?
2969
2956
self .__super_categories = list (super_categories )
2970
- if 'name' in kwds :
2971
- Category .__init__ (self , kwds ['name' ])
2972
- else :
2973
- Category .__init__ (self )
2957
+ Category .__init__ (self )
2974
2958
2975
2959
def _make_named_class_key (self , name ):
2976
2960
r"""
0 commit comments