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

Commit 54c3d67

Browse files
committed
#15801: Initialize the base ring for module homsets
1 parent d6dc1fd commit 54c3d67

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/sage/categories/homset.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,22 @@ def __init__(self, X, Y, category=None, base = None, check=True):
536536
Univariate Polynomial Ring in t over Integer Ring
537537
sage: f.domain() is f.parent().domain()
538538
True
539+
540+
Test that ``base_ring`` is initialized properly::
541+
542+
sage: R = QQ['x']
543+
sage: Hom(R, R).base_ring()
544+
Rational Field
545+
sage: Hom(R, R, category=Sets()).base_ring()
546+
sage: Hom(R, R, category=Modules(QQ)).base_ring()
547+
Rational Field
548+
sage: Hom(QQ^3, QQ^3, category=Modules(QQ)).base_ring()
549+
Rational Field
550+
551+
For whatever it's worth, the ``base`` arguments takes precedence::
552+
553+
sage: MyHomset(ZZ^3, ZZ^3, base = QQ).base_ring()
554+
Rational Field
539555
"""
540556
self._domain = X
541557
self._codomain = Y
@@ -550,6 +566,14 @@ def __init__(self, X, Y, category=None, base = None, check=True):
550566
#if not Y in category:
551567
# raise TypeError, "Y (=%s) must be in category (=%s)"%(Y, category)
552568

569+
if base is None and hasattr(category, "WithBasis"):
570+
# The above is a lame but fast check that category is a
571+
# subcategory of Modules(...). That will do until
572+
# CategoryObject.base_ring will be gone and not prevent
573+
# anymore from putting one in Modules.HomCategory.ParentMethods.
574+
# See also #15801.
575+
base = X.base_ring()
576+
553577
Parent.__init__(self, base = base, category = category.hom_category())
554578

555579
def __reduce__(self):

0 commit comments

Comments
 (0)