Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit c35a270

Browse files
committed
18174: more doc improvements + uniformization with CategoryWithAxiom
1 parent 1604162 commit c35a270

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/sage/categories/covariant_functorial_construction.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#******************************************************************************
4444
from sage.misc.cachefunc import cached_function, cached_method
4545
from sage.misc.lazy_attribute import lazy_class_attribute
46+
from sage.misc.lazy_import import LazyImport
4647
from sage.categories.category import Category
4748
from sage.structure.sage_object import SageObject
4849
from sage.structure.unique_representation import UniqueRepresentation
@@ -317,22 +318,37 @@ def __classget__(cls, base_category, base_category_class):
317318
``Category``, even if it has been overriden by a
318319
``Subquotients`` class.
319320
320-
TESTS::
321+
EXAMPLES::
321322
322323
sage: Sets.Subquotients
323324
<class 'sage.categories.sets_cat.Sets.Subquotients'>
324325
sage: Sets().Subquotients
325326
Cached version of <function Subquotients at ...>
326327
328+
This method also initializes the attribute
329+
``_base_category_class`` if not already set::
330+
331+
sage: Sets.Subquotients._base_category_class
332+
(<class 'sage.categories.sets_cat.Sets'>,)
333+
334+
It also forces the resolution of lazy imports (see :trac:`15648`)::
335+
336+
sage: type(Algebras.__dict__["Graded"])
337+
<type 'sage.misc.lazy_import.LazyImport'>
338+
sage: Algebras.Graded
339+
<class 'sage.categories.graded_algebras.GradedAlgebras'>
340+
sage: type(Algebras.__dict__["Graded"])
341+
<type 'sage.misc.classcall_metaclass.ClasscallMetaclass'>
342+
327343
.. TODO::
328344
329345
The logic is very similar to that implemented in
330346
:class:`CategoryWithAxiom.__classget__`. Find a way to
331347
refactor this to avoid the duplication.
332348
"""
333-
if base_category is None:
334-
return cls
335-
349+
if base_category is not None:
350+
assert base_category.__class__ is base_category_class
351+
assert isinstance(base_category_class, DynamicMetaclass)
336352
if isinstance(base_category_class, DynamicMetaclass):
337353
base_category_class = base_category_class.__base__
338354
if "_base_category_class" not in cls.__dict__:
@@ -342,6 +358,13 @@ def __classget__(cls, base_category, base_category_class):
342358
"base category class for {} mismatch; expected {}, got {}".format(
343359
cls, cls._base_category_class[0], base_category_class)
344360

361+
# Workaround #15648: if Sets.Subquotients is a LazyImport object,
362+
# this forces the substitution of the object back into Sets
363+
# to avoid resolving the lazy import over and over
364+
if isinstance(base_category_class.__dict__[cls._functor_category], LazyImport):
365+
setattr(base_category_class, cls._functor_category, cls)
366+
if base_category is None:
367+
return cls
345368
return getattr(super(base_category.__class__.__base__, base_category),
346369
cls._functor_category)
347370

0 commit comments

Comments
 (0)