Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

be more specific when raising "not a constant polynomial" #37747

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/map.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/categories/modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

::

Expand Down
2 changes: 1 addition & 1 deletion src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@
sage: b.dtype
dtype('int32') # 32-bit
dtype('int64') # 64-bit
sage: b.shape

Check warning on line 729 in src/sage/matrix/matrix1.pyx

View workflow job for this annotation

GitHub Actions / build

Warning: Variable 'b' referenced here was set only in doctest marked '# needs numpy'

Variable 'b' referenced here was set only in doctest marked '# needs numpy'
(3, 4)
"""
import numpy
Expand Down Expand Up @@ -1925,7 +1925,7 @@
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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/ore_polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3010,15 +3010,15 @@ 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:
return <Element>(x.constant_coefficient())
except AttributeError:
return <Element>((<OrePolynomial>x).constant_coefficient())
else:
raise TypeError("not a constant polynomial")
raise TypeError(f"not a constant polynomial: {x}")


cdef class OrePolynomialBaseringInjection(Morphism):
Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
"""
Expand All @@ -12913,15 +12913,15 @@ 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:
return <Element>(x.constant_coefficient())
except AttributeError:
return <Element>((<Polynomial>x).constant_coefficient())
else:
raise TypeError("not a constant polynomial")
raise TypeError(f"not a constant polynomial: {x}")

cdef class PolynomialBaseringInjection(Morphism):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/polynomial_zz_pex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
Loading