@@ -536,6 +536,22 @@ def __init__(self, X, Y, category=None, base = None, check=True):
536
536
Univariate Polynomial Ring in t over Integer Ring
537
537
sage: f.domain() is f.parent().domain()
538
538
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
539
555
"""
540
556
self ._domain = X
541
557
self ._codomain = Y
@@ -550,6 +566,14 @@ def __init__(self, X, Y, category=None, base = None, check=True):
550
566
#if not Y in category:
551
567
# raise TypeError, "Y (=%s) must be in category (=%s)"%(Y, category)
552
568
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
+
553
577
Parent .__init__ (self , base = base , category = category .hom_category ())
554
578
555
579
def __reduce__ (self ):
0 commit comments