diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-08-25 02:10:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-25 02:10:39 (GMT) |
commit | aef9ad82f7f667cd001a7112d3bc636e918626f7 (patch) | |
tree | 71bc842de3236a77c6084e951ecf6061693705c0 /Lib/test/clinic.test | |
parent | 805f8f9afea116c5d4d000570e3d02ae84502f43 (diff) | |
download | cpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.zip cpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.tar.gz cpython-aef9ad82f7f667cd001a7112d3bc636e918626f7.tar.bz2 |
bpo-37942: Improve argument clinic float converter (GH-15470)
Diffstat (limited to 'Lib/test/clinic.test')
-rw-r--r-- | Lib/test/clinic.test | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/Lib/test/clinic.test b/Lib/test/clinic.test index 62c2f00..ac6f419 100644 --- a/Lib/test/clinic.test +++ b/Lib/test/clinic.test @@ -1587,9 +1587,15 @@ test_float_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - a = (float) PyFloat_AsDouble(args[0]); - if (PyErr_Occurred()) { - goto exit; + if (PyFloat_CheckExact(args[0])) { + a = (float) (PyFloat_AS_DOUBLE(args[0])); + } + else + { + a = (float) PyFloat_AsDouble(args[0]); + if (a == -1.0 && PyErr_Occurred()) { + goto exit; + } } skip_optional: return_value = test_float_converter_impl(module, a); @@ -1600,7 +1606,7 @@ exit: static PyObject * test_float_converter_impl(PyObject *module, float a) -/*[clinic end generated code: output=8293566b2ec1fc52 input=259c0d98eca35034]*/ +/*[clinic end generated code: output=6b9c7443d2601cea input=259c0d98eca35034]*/ /*[clinic input] @@ -1634,9 +1640,15 @@ test_double_converter(PyObject *module, PyObject *const *args, Py_ssize_t nargs) if (nargs < 1) { goto skip_optional; } - a = PyFloat_AsDouble(args[0]); - if (PyErr_Occurred()) { - goto exit; + if (PyFloat_CheckExact(args[0])) { + a = PyFloat_AS_DOUBLE(args[0]); + } + else + { + a = PyFloat_AsDouble(args[0]); + if (a == -1.0 && PyErr_Occurred()) { + goto exit; + } } skip_optional: return_value = test_double_converter_impl(module, a); @@ -1647,7 +1659,7 @@ exit: static PyObject * test_double_converter_impl(PyObject *module, double a) -/*[clinic end generated code: output=487081a9b8da67ab input=c6a9945706a41c27]*/ +/*[clinic end generated code: output=5b7b9a0f0791b2cc input=c6a9945706a41c27]*/ /*[clinic input] |