From 16f7c094e48662c9ffc22a83fe66bb6e07d1057c Mon Sep 17 00:00:00 2001 From: Travis Scrimshaw Date: Mon, 5 Jun 2017 03:57:43 -0500 Subject: [PATCH] It is faster to check hasattr than to catch the exception. --- src/sage/rings/polynomial/polynomial_element.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index e832fc527a4..f73fb8954e5 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -7307,10 +7307,8 @@ cdef class Polynomial(CommutativeAlgebraElement): # If the base ring has a method _roots_univariate_polynomial, # try to use it. An exception is raised if the method does not # handle the current parameters - try: + if hasattr(K, '_roots_univariate_polynomial'): return K._roots_univariate_polynomial(self, ring=ring, multiplicities=multiplicities, algorithm=algorithm, **kwds) - except (AttributeError, NotImplementedError): - pass if kwds: raise TypeError("roots() got unexpected keyword argument(s): {}".format(kwds.keys()))