# HG changeset patch
# User Xavier Caruso
# Date 1341738209 -7200
# Node ID 09ba9b7f74b31e781e40c0f2bbe765e6c9c7bdb2
# Parent c4bdbf18dd78c13ff3032e07a3f355b8632ac054
Trac #13184: Unique parent assumption for homset
diff --git a/sage/categories/homset.py b/sage/categories/homset.py
--- a/sage/categories/homset.py
+++ b/sage/categories/homset.py
@@ -154,9 +154,17 @@
TESTS:
- Some doc tests in :mod:`sage.rings` (need to) break the unique parent assumption.
- But if domain or codomain are not unique parents, then the hom set won't fit.
- That's to say, the hom set found in the cache will have a (co)domain that is
+ Homset are unique parents::
+
+ sage: k = GF(5)
+ sage: H1 = Hom(k,k)
+ sage: H2 = Hom(k,k)
+ sage: H1 is H2
+ True
+
+ However, some doc tests in :mod:`sage.rings` (need to) break the unique parent
+ assumption. If domain or codomain are not unique parents, then the hom set won't
+ fit. That's to say, the hom set found in the cache will have a (co)domain that is
equal to, but not identic with, the given (co)domain.
By trac ticket #9138, we abandon the uniqueness of hom sets, if the domain or
@@ -221,8 +229,12 @@
return H
try:
- # Apparently X._Hom_ is supposed to be cached
- return X._Hom_(Y, category)
+ # Actually X._Hom_ is supposed to be cached
+ # but it is not in some cases (e.g. X is a finite field)
+ # To be investigated
+ H = X._Hom_(Y,category)
+ _cache[key] = weakref.ref(H)
+ return H
except (AttributeError, TypeError):
pass