diff --git a/src/sage/functions/other.py b/src/sage/functions/other.py index b69c0570799..d1c6dfa356a 100644 --- a/src/sage/functions/other.py +++ b/src/sage/functions/other.py @@ -1101,7 +1101,7 @@ def gamma(a, *args, **kwds): sage: gamma(i) Traceback (most recent call last): ... - TypeError: cannot coerce arguments: no canonical coercion... + TypeError: cannot convert arguments: no canonical coercion... TESTS:: diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 81e45837865..298acaffc93 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -76,7 +76,7 @@ cdef class Function(SageObject): sage: bar(x) Traceback (most recent call last): ... - TypeError: function did not return a symbolic expression or an element that can be coerced into a symbolic expression + TypeError: function did not return a symbolic expression or an element that can be converted into a symbolic expression # eval_func is not callable sage: bar = function("bar", nargs=1, eval_func=5) @@ -389,11 +389,11 @@ cdef class Function(SageObject): sage: bar(ZZ) Traceback (most recent call last): ... - TypeError: cannot coerce arguments: ... + TypeError: cannot convert arguments: ... sage: exp(QQbar(I)) 0.540302305868140 + 0.841470984807897*I sage: binomial(Qp(2)(9),5) - 126 + 2 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 + O(2^21) For functions with single argument, if coercion fails we try to call a method with the name of the function on the object:: @@ -470,29 +470,17 @@ cdef class Function(SageObject): method = getattr(args[0], self._name, None) if callable(method): return method() - raise TypeError("cannot coerce arguments: %s" % (err)) - - # There is no natural coercion from QQbar to the symbolic ring - # in order to support - # sage: QQbar(sqrt(2)) + sqrt(3) - # 3.146264369941973? - # to work around this limitation, we manually convert - # elements of QQbar to symbolic expressions here - from sage.rings.qqbar import QQbar, AA - from sage.rings.padics.padic_generic_element import pAdicGenericElement + nargs = [None]*len(args) for i in range(len(args)): carg = args[i] - if (isinstance(carg, Element) and - ((carg)._parent is QQbar or - (carg)._parent is AA or - isinstance(carg, pAdicGenericElement))): - nargs[i] = SR(carg) - else: + try: + nargs[i] = SR.coerce(carg) + except TypeError: try: - nargs[i] = SR.coerce(carg) - except Exception: - raise TypeError, "cannot coerce arguments: %s"%(err) + nargs[i] = SR(carg) + except TypeError: + raise TypeError("cannot convert arguments: %s" % (err)) args = nargs else: # coerce == False for a in args: diff --git a/src/sage/symbolic/pynac.pyx b/src/sage/symbolic/pynac.pyx index 3a38a7ecdc3..c897386d9ab 100644 --- a/src/sage/symbolic/pynac.pyx +++ b/src/sage/symbolic/pynac.pyx @@ -179,7 +179,10 @@ cdef GEx pyExpression_to_ex(object res) except *: try: t = ring.SR.coerce(res) except TypeError as err: - raise TypeError("function did not return a symbolic expression or an element that can be coerced into a symbolic expression") + try: + t = ring.SR(res) + except TypeError: + raise TypeError("function did not return a symbolic expression or an element that can be converted into a symbolic expression") return (t)._gobj cdef object paramset_to_PyTuple(const_paramset_ref s):