From d969885c8d473a5ec98b89fc9be3bcd827aecee7 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Thu, 4 Apr 2024 20:10:58 +0200 Subject: [PATCH 1/4] be more specific also for ore polynomials, adapt doctests --- src/sage/categories/action.pyx | 4 ++-- src/sage/categories/map.pyx | 2 +- src/sage/categories/modules_with_basis.py | 2 +- .../dynamics/arithmetic_dynamics/dynamical_semigroup.py | 2 +- src/sage/matrix/matrix1.pyx | 2 +- src/sage/rings/polynomial/ore_polynomial_element.pyx | 4 ++-- src/sage/rings/polynomial/polynomial_element.pyx | 8 ++++---- src/sage/rings/polynomial/polynomial_zz_pex.pyx | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 3b3ba9d463b..9a9f9c45668 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -148,7 +148,7 @@ cdef class Action(Functor): sage: A(x, 5) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: x sage: A = IntegerMulAction(ZZ, R, False) # Right action sage: A(x, 5) 5*x @@ -157,7 +157,7 @@ cdef class Action(Functor): sage: A(5, x) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: x """ if len(args) == 2: # Normal case, called with (g, x) or (x, g) as arguments diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 29613f16285..e687cad229b 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -2087,7 +2087,7 @@ cdef class FormalCompositeMap(Map): sage: ZZ(3*x + 45) # indirect doctest Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: 3*x + 45 """ sections = [] for m in reversed(list(self)): diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index e1fa796ba3b..4d9049e1894 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -1332,7 +1332,7 @@ def _from_dict(self, d, coerce=True, remove_zeros=True): sage: A._from_dict(d, coerce=True) # needs sage.modules Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: y """ R = self.base_ring() B = self.basis() diff --git a/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py b/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py index ebb8702a7db..a12c2d257fb 100644 --- a/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py +++ b/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py @@ -697,7 +697,7 @@ def orbit(self, p, n): sage: d.orbit(2, x) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: x :: diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index b15eb21da77..e13114eb849 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -1925,7 +1925,7 @@ cdef class Matrix(Matrix0): sage: D = A.augment(B) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: y sage: E = A.change_ring(R) sage: F = E.augment(B); F diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 86c2a057353..d5c429b4d8e 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -3010,7 +3010,7 @@ cdef class ConstantOrePolynomialSection(Map): sage: m(S([0,1])-S([0,t])) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: (-t + 1)*x """ if x.degree() <= 0: try: @@ -3018,7 +3018,7 @@ cdef class ConstantOrePolynomialSection(Map): except AttributeError: return ((x).constant_coefficient()) else: - raise TypeError("not a constant polynomial") + raise TypeError(f"not a constant polynomial: {x}") cdef class OrePolynomialBaseringInjection(Morphism): diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 8b58e403d3d..7c5646aa267 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -1476,7 +1476,7 @@ cdef class Polynomial(CommutativePolynomial): sage: QQ(3*x + 45) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: 3*x + 45 """ return self._scalar_conversion(sage.rings.rational.Rational) @@ -12894,7 +12894,7 @@ cdef class ConstantPolynomialSection(Map): sage: phi(y_1) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: y_1 """ cpdef Element _call_(self, x) noexcept: """ @@ -12913,7 +12913,7 @@ cdef class ConstantPolynomialSection(Map): sage: m(x) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: x """ if x.degree() <= 0: try: @@ -12921,7 +12921,7 @@ cdef class ConstantPolynomialSection(Map): except AttributeError: return ((x).constant_coefficient()) else: - raise TypeError("not a constant polynomial") + raise TypeError(f"not a constant polynomial: {x}") cdef class PolynomialBaseringInjection(Morphism): """ diff --git a/src/sage/rings/polynomial/polynomial_zz_pex.pyx b/src/sage/rings/polynomial/polynomial_zz_pex.pyx index 9a0384c643b..0f588b48d89 100644 --- a/src/sage/rings/polynomial/polynomial_zz_pex.pyx +++ b/src/sage/rings/polynomial/polynomial_zz_pex.pyx @@ -99,7 +99,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): sage: R([3,x]) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: x Check that NTL contexts are correctly restored and that :issue:`9524` has been fixed:: From 14045bf73ae13f871812a5ca47b080f2a3e64c3a Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Fri, 5 Apr 2024 01:11:17 +0200 Subject: [PATCH 2/4] fix doctest --- src/doc/en/thematic_tutorials/coercion_and_categories.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/en/thematic_tutorials/coercion_and_categories.rst b/src/doc/en/thematic_tutorials/coercion_and_categories.rst index edd89ad3c42..f6cb67993ac 100644 --- a/src/doc/en/thematic_tutorials/coercion_and_categories.rst +++ b/src/doc/en/thematic_tutorials/coercion_and_categories.rst @@ -837,7 +837,7 @@ The four axioms requested for coercions sage: ZZ(P2.gen(1)) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: not a constant polynomial: v Hence, we only have a *partial* map. This is fine for a *conversion*, but a partial map does not qualify as a *coercion*. From 5e0ba2b2bc8b816537b95a2663160a17ca193259 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Fri, 5 Apr 2024 15:30:12 +0200 Subject: [PATCH 3/4] improve error message --- src/doc/en/thematic_tutorials/coercion_and_categories.rst | 2 +- src/sage/categories/action.pyx | 4 ++-- src/sage/categories/map.pyx | 2 +- src/sage/categories/modules_with_basis.py | 2 +- .../dynamics/arithmetic_dynamics/dynamical_semigroup.py | 2 +- src/sage/matrix/matrix1.pyx | 2 +- src/sage/rings/polynomial/ore_function_element.py | 4 ++-- src/sage/rings/polynomial/ore_polynomial_element.pyx | 4 ++-- src/sage/rings/polynomial/polynomial_element.pyx | 8 ++++---- src/sage/rings/polynomial/polynomial_zz_pex.pyx | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/doc/en/thematic_tutorials/coercion_and_categories.rst b/src/doc/en/thematic_tutorials/coercion_and_categories.rst index f6cb67993ac..afa83bfa754 100644 --- a/src/doc/en/thematic_tutorials/coercion_and_categories.rst +++ b/src/doc/en/thematic_tutorials/coercion_and_categories.rst @@ -837,7 +837,7 @@ The four axioms requested for coercions sage: ZZ(P2.gen(1)) Traceback (most recent call last): ... - TypeError: not a constant polynomial: v + TypeError: v is not a constant polynomial Hence, we only have a *partial* map. This is fine for a *conversion*, but a partial map does not qualify as a *coercion*. diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index 9a9f9c45668..4a026093411 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -148,7 +148,7 @@ cdef class Action(Functor): sage: A(x, 5) Traceback (most recent call last): ... - TypeError: not a constant polynomial: x + TypeError: x is not a constant polynomial sage: A = IntegerMulAction(ZZ, R, False) # Right action sage: A(x, 5) 5*x @@ -157,7 +157,7 @@ cdef class Action(Functor): sage: A(5, x) Traceback (most recent call last): ... - TypeError: not a constant polynomial: x + TypeError: x is not a constant polynomial """ if len(args) == 2: # Normal case, called with (g, x) or (x, g) as arguments diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index e687cad229b..439c7cf0ac9 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -2087,7 +2087,7 @@ cdef class FormalCompositeMap(Map): sage: ZZ(3*x + 45) # indirect doctest Traceback (most recent call last): ... - TypeError: not a constant polynomial: 3*x + 45 + TypeError: 3*x + 45 is not a constant polynomial """ sections = [] for m in reversed(list(self)): diff --git a/src/sage/categories/modules_with_basis.py b/src/sage/categories/modules_with_basis.py index 4d9049e1894..fda93510d07 100644 --- a/src/sage/categories/modules_with_basis.py +++ b/src/sage/categories/modules_with_basis.py @@ -1332,7 +1332,7 @@ def _from_dict(self, d, coerce=True, remove_zeros=True): sage: A._from_dict(d, coerce=True) # needs sage.modules Traceback (most recent call last): ... - TypeError: not a constant polynomial: y + TypeError: y is not a constant polynomial """ R = self.base_ring() B = self.basis() diff --git a/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py b/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py index a12c2d257fb..93c402d4695 100644 --- a/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py +++ b/src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py @@ -697,7 +697,7 @@ def orbit(self, p, n): sage: d.orbit(2, x) Traceback (most recent call last): ... - TypeError: not a constant polynomial: x + TypeError: x is not a constant polynomial :: diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index e13114eb849..231b6f50333 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -1925,7 +1925,7 @@ cdef class Matrix(Matrix0): sage: D = A.augment(B) Traceback (most recent call last): ... - TypeError: not a constant polynomial: y + TypeError: y is not a constant polynomial sage: E = A.change_ring(R) sage: F = E.augment(B); F diff --git a/src/sage/rings/polynomial/ore_function_element.py b/src/sage/rings/polynomial/ore_function_element.py index f44dd8ad880..0c1a919351f 100644 --- a/src/sage/rings/polynomial/ore_function_element.py +++ b/src/sage/rings/polynomial/ore_function_element.py @@ -708,13 +708,13 @@ def _call_(self, x): sage: F(g) # needs sage.rings.function_field Traceback (most recent call last): ... - TypeError: not a constant function + TypeError: (x + t^2)^(-1) * x is not a constant function """ numerator = x._numerator denominator = x._denominator if numerator.degree() == denominator.degree() and denominator.right_divides(numerator): return numerator.leading_coefficient() / denominator.leading_coefficient() - raise TypeError("not a constant function") + raise TypeError(f"{x} is not a constant function") class OreFunctionBaseringInjection(Morphism): r""" diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index d5c429b4d8e..00fa90f2d11 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -3010,7 +3010,7 @@ cdef class ConstantOrePolynomialSection(Map): sage: m(S([0,1])-S([0,t])) Traceback (most recent call last): ... - TypeError: not a constant polynomial: (-t + 1)*x + TypeError: (-t + 1)*x is not a constant polynomial """ if x.degree() <= 0: try: @@ -3018,7 +3018,7 @@ cdef class ConstantOrePolynomialSection(Map): except AttributeError: return ((x).constant_coefficient()) else: - raise TypeError(f"not a constant polynomial: {x}") + raise TypeError(f"{x} is not a constant polynomial") cdef class OrePolynomialBaseringInjection(Morphism): diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 7c5646aa267..d2b8159696e 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -1476,7 +1476,7 @@ cdef class Polynomial(CommutativePolynomial): sage: QQ(3*x + 45) Traceback (most recent call last): ... - TypeError: not a constant polynomial: 3*x + 45 + TypeError: 3*x + 45 is not a constant polynomial """ return self._scalar_conversion(sage.rings.rational.Rational) @@ -12894,7 +12894,7 @@ cdef class ConstantPolynomialSection(Map): sage: phi(y_1) Traceback (most recent call last): ... - TypeError: not a constant polynomial: y_1 + TypeError: y_1 is not a constant polynomial """ cpdef Element _call_(self, x) noexcept: """ @@ -12913,7 +12913,7 @@ cdef class ConstantPolynomialSection(Map): sage: m(x) Traceback (most recent call last): ... - TypeError: not a constant polynomial: x + TypeError: x is not a constant polynomial """ if x.degree() <= 0: try: @@ -12921,7 +12921,7 @@ cdef class ConstantPolynomialSection(Map): except AttributeError: return ((x).constant_coefficient()) else: - raise TypeError(f"not a constant polynomial: {x}") + raise TypeError(f"{x} is not a constant polynomial") cdef class PolynomialBaseringInjection(Morphism): """ diff --git a/src/sage/rings/polynomial/polynomial_zz_pex.pyx b/src/sage/rings/polynomial/polynomial_zz_pex.pyx index 0f588b48d89..e7ad9e35686 100644 --- a/src/sage/rings/polynomial/polynomial_zz_pex.pyx +++ b/src/sage/rings/polynomial/polynomial_zz_pex.pyx @@ -99,7 +99,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): sage: R([3,x]) Traceback (most recent call last): ... - TypeError: not a constant polynomial: x + TypeError: x is not a constant polynomial Check that NTL contexts are correctly restored and that :issue:`9524` has been fixed:: From 14304926b22ea66bb4fd4427a64f8cc9cdd2c0e9 Mon Sep 17 00:00:00 2001 From: Martin Rubey Date: Wed, 17 Apr 2024 13:09:08 +0200 Subject: [PATCH 4/4] fix doctest --- src/sage/combinat/sf/sfa.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index 56a32dea180..afa2e6653e7 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -6636,7 +6636,7 @@ def _apply_functor(self, R): sage: F(QQ) Traceback (most recent call last): ... - TypeError: not a constant polynomial + TypeError: t is not a constant polynomial """ from sage.combinat.sf.sf import SymmetricFunctions return self._basis(self._family(SymmetricFunctions(R), *self._args))