Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sagemathgh-37034: raise ValueError instead of IndexError in .any_root()
The `.any_root()` method sometimes raises an `IndexError` instead of the usual `ValueError` when no root exists. Example (Sage 10.2): ```sage sage: R.<x> = Zmod(55)[] sage: (x^2 + 1).any_root() ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[2], line 1 ----> 1 (x**Integer(2)+Integer(1)).any_root() File /usr/lib/python3.11/site- packages/sage/rings/polynomial/polynomial_element.pyx:2315, in sage.rings.polynomial.polynomial_element.Polynomial.any_root (build/cythonized/sage/rings/polynomial/polynomial_element.c:34795)() 2313 return (self//h).any_root(ring, -degree, True) 2314 else: -> 2315 return self.roots(ring=ring, multiplicities=False)[0] 2316 2317 def __truediv__(left, right): IndexError: list index out of range ``` With this patch, we check for the `IndexError` before it happens and raise a `ValueError` instead. URL: sagemath#37034 Reported by: Lorenz Panny Reviewer(s): Travis Scrimshaw
- Loading branch information