From 769c65f2694884768677608a9ae61453945f24e3 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 25 Oct 2024 09:03:58 +0300 Subject: [PATCH 1/4] gh-125957: sync argument naming in sphinx docs of the cmath and help() --- Doc/library/cmath.rst | 100 +++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/Doc/library/cmath.rst b/Doc/library/cmath.rst index 381a8332f4b187..d3b3f5d476c3f2 100644 --- a/Doc/library/cmath.rst +++ b/Doc/library/cmath.rst @@ -55,13 +55,13 @@ segment that joins the origin to *z*. The following functions can be used to convert from the native rectangular coordinates to polar coordinates and back. -.. function:: phase(x) +.. function:: phase(z) - Return the phase of *x* (also known as the *argument* of *x*), as a float. - ``phase(x)`` is equivalent to ``math.atan2(x.imag, x.real)``. The result + Return the phase of *z* (also known as the *argument* of *z*), as a float. + ``phase(z)`` is equivalent to ``math.atan2(z.imag, z.real)``. The result lies in the range [-\ *π*, *π*], and the branch cut for this operation lies along the negative real axis. The sign of the result is the same as the - sign of ``x.imag``, even when ``x.imag`` is zero:: + sign of ``z.imag``, even when ``z.imag`` is zero:: >>> phase(complex(-1.0, 0.0)) 3.141592653589793 @@ -71,147 +71,147 @@ rectangular coordinates to polar coordinates and back. .. note:: - The modulus (absolute value) of a complex number *x* can be + The modulus (absolute value) of a complex number *z* can be computed using the built-in :func:`abs` function. There is no separate :mod:`cmath` module function for this operation. -.. function:: polar(x) +.. function:: polar(z) - Return the representation of *x* in polar coordinates. Returns a - pair ``(r, phi)`` where *r* is the modulus of *x* and phi is the - phase of *x*. ``polar(x)`` is equivalent to ``(abs(x), - phase(x))``. + Return the representation of *z* in polar coordinates. Returns a + pair ``(r, phi)`` where *r* is the modulus of *z* and phi is the + phase of *z*. ``polar(z)`` is equivalent to ``(abs(z), + phase(z))``. .. function:: rect(r, phi) - Return the complex number *x* with polar coordinates *r* and *phi*. + Return the complex number *z* with polar coordinates *r* and *phi*. Equivalent to ``complex(r * math.cos(phi), r * math.sin(phi))``. Power and logarithmic functions ------------------------------- -.. function:: exp(x) +.. function:: exp(z) - Return *e* raised to the power *x*, where *e* is the base of natural + Return *e* raised to the power *z*, where *e* is the base of natural logarithms. -.. function:: log(x[, base]) +.. function:: log(z[, base]) - Returns the logarithm of *x* to the given *base*. If the *base* is not - specified, returns the natural logarithm of *x*. There is one branch cut, + Returns the logarithm of *z* to the given *base*. If the *base* is not + specified, returns the natural logarithm of *z*. There is one branch cut, from 0 along the negative real axis to -∞. -.. function:: log10(x) +.. function:: log10(z) - Return the base-10 logarithm of *x*. This has the same branch cut as + Return the base-10 logarithm of *z*. This has the same branch cut as :func:`log`. -.. function:: sqrt(x) +.. function:: sqrt(z) - Return the square root of *x*. This has the same branch cut as :func:`log`. + Return the square root of *z*. This has the same branch cut as :func:`log`. Trigonometric functions ----------------------- -.. function:: acos(x) +.. function:: acos(z) - Return the arc cosine of *x*. There are two branch cuts: One extends right + Return the arc cosine of *z*. There are two branch cuts: One extends right from 1 along the real axis to ∞. The other extends left from -1 along the real axis to -∞. -.. function:: asin(x) +.. function:: asin(z) - Return the arc sine of *x*. This has the same branch cuts as :func:`acos`. + Return the arc sine of *z*. This has the same branch cuts as :func:`acos`. -.. function:: atan(x) +.. function:: atan(z) - Return the arc tangent of *x*. There are two branch cuts: One extends from + Return the arc tangent of *z*. There are two branch cuts: One extends from ``1j`` along the imaginary axis to ``∞j``. The other extends from ``-1j`` along the imaginary axis to ``-∞j``. -.. function:: cos(x) +.. function:: cos(z) - Return the cosine of *x*. + Return the cosine of *z*. -.. function:: sin(x) +.. function:: sin(z) - Return the sine of *x*. + Return the sine of *z*. -.. function:: tan(x) +.. function:: tan(z) - Return the tangent of *x*. + Return the tangent of *z*. Hyperbolic functions -------------------- -.. function:: acosh(x) +.. function:: acosh(z) - Return the inverse hyperbolic cosine of *x*. There is one branch cut, + Return the inverse hyperbolic cosine of *z*. There is one branch cut, extending left from 1 along the real axis to -∞. -.. function:: asinh(x) +.. function:: asinh(z) - Return the inverse hyperbolic sine of *x*. There are two branch cuts: + Return the inverse hyperbolic sine of *z*. There are two branch cuts: One extends from ``1j`` along the imaginary axis to ``∞j``. The other extends from ``-1j`` along the imaginary axis to ``-∞j``. -.. function:: atanh(x) +.. function:: atanh(z) - Return the inverse hyperbolic tangent of *x*. There are two branch cuts: One + Return the inverse hyperbolic tangent of *z*. There are two branch cuts: One extends from ``1`` along the real axis to ``∞``. The other extends from ``-1`` along the real axis to ``-∞``. -.. function:: cosh(x) +.. function:: cosh(z) - Return the hyperbolic cosine of *x*. + Return the hyperbolic cosine of *z*. -.. function:: sinh(x) +.. function:: sinh(z) - Return the hyperbolic sine of *x*. + Return the hyperbolic sine of *z*. -.. function:: tanh(x) +.. function:: tanh(z) - Return the hyperbolic tangent of *x*. + Return the hyperbolic tangent of *z*. Classification functions ------------------------ -.. function:: isfinite(x) +.. function:: isfinite(z) - Return ``True`` if both the real and imaginary parts of *x* are finite, and + Return ``True`` if both the real and imaginary parts of *z* are finite, and ``False`` otherwise. .. versionadded:: 3.2 -.. function:: isinf(x) +.. function:: isinf(z) - Return ``True`` if either the real or the imaginary part of *x* is an + Return ``True`` if either the real or the imaginary part of *z* is an infinity, and ``False`` otherwise. -.. function:: isnan(x) +.. function:: isnan(z) - Return ``True`` if either the real or the imaginary part of *x* is a NaN, + Return ``True`` if either the real or the imaginary part of *z* is a NaN, and ``False`` otherwise. From f34de6af4d0428d68422ab95c8e57db68d9022d0 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 25 Oct 2024 09:10:28 +0300 Subject: [PATCH 2/4] + allow cmath.sin(z=1) syntax In the main: $ ./python -m timeit -r11 -s 'from cmath import sin;z=1j' 'sin(z)' 1000000 loops, best of 11: 312 nsec per loop With patch: $ ./python -m timeit -r11 -s 'from cmath import sin;z=1j' 'sin(z)' 1000000 loops, best of 11: 330 nsec per loop --- Modules/clinic/cmathmodule.c.h | 616 +++++++++++++++++++++++++++++---- Modules/cmathmodule.c | 6 +- 2 files changed, 549 insertions(+), 73 deletions(-) diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h index 50745fd4f407a3..9286d573808839 100644 --- a/Modules/clinic/cmathmodule.c.h +++ b/Modules/clinic/cmathmodule.c.h @@ -6,28 +6,58 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_modsupport.h" // _PyArg_CheckPositional() +#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(cmath_acos__doc__, -"acos($module, z, /)\n" +"acos($module, /, z)\n" "--\n" "\n" "Return the arc cosine of z."); #define CMATH_ACOS_METHODDEF \ - {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__}, + {"acos", _PyCFunction_CAST(cmath_acos), METH_FASTCALL|METH_KEYWORDS, cmath_acos__doc__}, static Py_complex cmath_acos_impl(PyObject *module, Py_complex z); static PyObject * -cmath_acos(PyObject *module, PyObject *arg) +cmath_acos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "acos", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -51,25 +81,55 @@ cmath_acos(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_acosh__doc__, -"acosh($module, z, /)\n" +"acosh($module, /, z)\n" "--\n" "\n" "Return the inverse hyperbolic cosine of z."); #define CMATH_ACOSH_METHODDEF \ - {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__}, + {"acosh", _PyCFunction_CAST(cmath_acosh), METH_FASTCALL|METH_KEYWORDS, cmath_acosh__doc__}, static Py_complex cmath_acosh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_acosh(PyObject *module, PyObject *arg) +cmath_acosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "acosh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -93,25 +153,55 @@ cmath_acosh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_asin__doc__, -"asin($module, z, /)\n" +"asin($module, /, z)\n" "--\n" "\n" "Return the arc sine of z."); #define CMATH_ASIN_METHODDEF \ - {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__}, + {"asin", _PyCFunction_CAST(cmath_asin), METH_FASTCALL|METH_KEYWORDS, cmath_asin__doc__}, static Py_complex cmath_asin_impl(PyObject *module, Py_complex z); static PyObject * -cmath_asin(PyObject *module, PyObject *arg) +cmath_asin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "asin", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -135,25 +225,55 @@ cmath_asin(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_asinh__doc__, -"asinh($module, z, /)\n" +"asinh($module, /, z)\n" "--\n" "\n" "Return the inverse hyperbolic sine of z."); #define CMATH_ASINH_METHODDEF \ - {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__}, + {"asinh", _PyCFunction_CAST(cmath_asinh), METH_FASTCALL|METH_KEYWORDS, cmath_asinh__doc__}, static Py_complex cmath_asinh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_asinh(PyObject *module, PyObject *arg) +cmath_asinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "asinh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -177,25 +297,55 @@ cmath_asinh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_atan__doc__, -"atan($module, z, /)\n" +"atan($module, /, z)\n" "--\n" "\n" "Return the arc tangent of z."); #define CMATH_ATAN_METHODDEF \ - {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__}, + {"atan", _PyCFunction_CAST(cmath_atan), METH_FASTCALL|METH_KEYWORDS, cmath_atan__doc__}, static Py_complex cmath_atan_impl(PyObject *module, Py_complex z); static PyObject * -cmath_atan(PyObject *module, PyObject *arg) +cmath_atan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "atan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -219,25 +369,55 @@ cmath_atan(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_atanh__doc__, -"atanh($module, z, /)\n" +"atanh($module, /, z)\n" "--\n" "\n" "Return the inverse hyperbolic tangent of z."); #define CMATH_ATANH_METHODDEF \ - {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__}, + {"atanh", _PyCFunction_CAST(cmath_atanh), METH_FASTCALL|METH_KEYWORDS, cmath_atanh__doc__}, static Py_complex cmath_atanh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_atanh(PyObject *module, PyObject *arg) +cmath_atanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "atanh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -261,25 +441,55 @@ cmath_atanh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_cos__doc__, -"cos($module, z, /)\n" +"cos($module, /, z)\n" "--\n" "\n" "Return the cosine of z."); #define CMATH_COS_METHODDEF \ - {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__}, + {"cos", _PyCFunction_CAST(cmath_cos), METH_FASTCALL|METH_KEYWORDS, cmath_cos__doc__}, static Py_complex cmath_cos_impl(PyObject *module, Py_complex z); static PyObject * -cmath_cos(PyObject *module, PyObject *arg) +cmath_cos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "cos", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -303,25 +513,55 @@ cmath_cos(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_cosh__doc__, -"cosh($module, z, /)\n" +"cosh($module, /, z)\n" "--\n" "\n" "Return the hyperbolic cosine of z."); #define CMATH_COSH_METHODDEF \ - {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__}, + {"cosh", _PyCFunction_CAST(cmath_cosh), METH_FASTCALL|METH_KEYWORDS, cmath_cosh__doc__}, static Py_complex cmath_cosh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_cosh(PyObject *module, PyObject *arg) +cmath_cosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "cosh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -345,25 +585,55 @@ cmath_cosh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_exp__doc__, -"exp($module, z, /)\n" +"exp($module, /, z)\n" "--\n" "\n" "Return the exponential value e**z."); #define CMATH_EXP_METHODDEF \ - {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__}, + {"exp", _PyCFunction_CAST(cmath_exp), METH_FASTCALL|METH_KEYWORDS, cmath_exp__doc__}, static Py_complex cmath_exp_impl(PyObject *module, Py_complex z); static PyObject * -cmath_exp(PyObject *module, PyObject *arg) +cmath_exp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "exp", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -387,25 +657,55 @@ cmath_exp(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_log10__doc__, -"log10($module, z, /)\n" +"log10($module, /, z)\n" "--\n" "\n" "Return the base-10 logarithm of z."); #define CMATH_LOG10_METHODDEF \ - {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__}, + {"log10", _PyCFunction_CAST(cmath_log10), METH_FASTCALL|METH_KEYWORDS, cmath_log10__doc__}, static Py_complex cmath_log10_impl(PyObject *module, Py_complex z); static PyObject * -cmath_log10(PyObject *module, PyObject *arg) +cmath_log10(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "log10", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -429,25 +729,55 @@ cmath_log10(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_sin__doc__, -"sin($module, z, /)\n" +"sin($module, /, z)\n" "--\n" "\n" "Return the sine of z."); #define CMATH_SIN_METHODDEF \ - {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__}, + {"sin", _PyCFunction_CAST(cmath_sin), METH_FASTCALL|METH_KEYWORDS, cmath_sin__doc__}, static Py_complex cmath_sin_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sin(PyObject *module, PyObject *arg) +cmath_sin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "sin", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -471,25 +801,55 @@ cmath_sin(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_sinh__doc__, -"sinh($module, z, /)\n" +"sinh($module, /, z)\n" "--\n" "\n" "Return the hyperbolic sine of z."); #define CMATH_SINH_METHODDEF \ - {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__}, + {"sinh", _PyCFunction_CAST(cmath_sinh), METH_FASTCALL|METH_KEYWORDS, cmath_sinh__doc__}, static Py_complex cmath_sinh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sinh(PyObject *module, PyObject *arg) +cmath_sinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "sinh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -513,25 +873,55 @@ cmath_sinh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_sqrt__doc__, -"sqrt($module, z, /)\n" +"sqrt($module, /, z)\n" "--\n" "\n" "Return the square root of z."); #define CMATH_SQRT_METHODDEF \ - {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__}, + {"sqrt", _PyCFunction_CAST(cmath_sqrt), METH_FASTCALL|METH_KEYWORDS, cmath_sqrt__doc__}, static Py_complex cmath_sqrt_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sqrt(PyObject *module, PyObject *arg) +cmath_sqrt(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "sqrt", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -555,25 +945,55 @@ cmath_sqrt(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_tan__doc__, -"tan($module, z, /)\n" +"tan($module, /, z)\n" "--\n" "\n" "Return the tangent of z."); #define CMATH_TAN_METHODDEF \ - {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__}, + {"tan", _PyCFunction_CAST(cmath_tan), METH_FASTCALL|METH_KEYWORDS, cmath_tan__doc__}, static Py_complex cmath_tan_impl(PyObject *module, Py_complex z); static PyObject * -cmath_tan(PyObject *module, PyObject *arg) +cmath_tan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "tan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -597,25 +1017,55 @@ cmath_tan(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_tanh__doc__, -"tanh($module, z, /)\n" +"tanh($module, /, z)\n" "--\n" "\n" "Return the hyperbolic tangent of z."); #define CMATH_TANH_METHODDEF \ - {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__}, + {"tanh", _PyCFunction_CAST(cmath_tanh), METH_FASTCALL|METH_KEYWORDS, cmath_tanh__doc__}, static Py_complex cmath_tanh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_tanh(PyObject *module, PyObject *arg) +cmath_tanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "tanh", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - z = PyComplex_AsCComplex(arg); + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -639,7 +1089,7 @@ cmath_tanh(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_log__doc__, -"log($module, z, base=, /)\n" +"log($module, /, z, base=)\n" "--\n" "\n" "log(z[, base]) -> the logarithm of z to the given base.\n" @@ -647,30 +1097,58 @@ PyDoc_STRVAR(cmath_log__doc__, "If the base is not specified, returns the natural logarithm (base e) of z."); #define CMATH_LOG_METHODDEF \ - {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__}, + {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL|METH_KEYWORDS, cmath_log__doc__}, static PyObject * cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj); static PyObject * -cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + #define NUM_KEYWORDS 2 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { _Py_LATIN1_CHR('z'), &_Py_ID(base), }, + }; + #undef NUM_KEYWORDS + #define KWTUPLE (&_kwtuple.ob_base.ob_base) + + #else // !Py_BUILD_CORE + # define KWTUPLE NULL + #endif // !Py_BUILD_CORE + + static const char * const _keywords[] = {"z", "base", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "log", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; + Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; Py_complex x; PyObject *y_obj = NULL; - if (!_PyArg_CheckPositional("log", nargs, 1, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); + if (!args) { goto exit; } x = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } - if (nargs < 2) { - goto skip_optional; + if (!noptargs) { + goto skip_optional_pos; } y_obj = args[1]; -skip_optional: +skip_optional_pos: return_value = cmath_log_impl(module, x, y_obj); exit: @@ -982,4 +1460,4 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=454309b21cfa9bf6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=bc927b0141508062 input=a9049054013a1b77]*/ diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index e07c2dbd262354..6fb701860e8ac6 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -169,14 +169,13 @@ static Py_complex acos_special_values[7][7]; cmath.acos -> Py_complex_protected z: Py_complex_protected - / Return the arc cosine of z. [clinic start generated code]*/ static Py_complex cmath_acos_impl(PyObject *module, Py_complex z) -/*[clinic end generated code: output=40bd42853fd460ae input=bd6cbd78ae851927]*/ +/*[clinic end generated code: output=40bd42853fd460ae input=825ee8128f5c21e2]*/ { Py_complex s1, s2, r; @@ -865,7 +864,6 @@ cmath.log z as x: Py_complex base as y_obj: object = NULL - / log(z[, base]) -> the logarithm of z to the given base. @@ -874,7 +872,7 @@ If the base is not specified, returns the natural logarithm (base e) of z. static PyObject * cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj) -/*[clinic end generated code: output=4effdb7d258e0d94 input=e1f81d4fcfd26497]*/ +/*[clinic end generated code: output=4effdb7d258e0d94 input=62e46be565758323]*/ { Py_complex y; From 57cc455048f44b13202fcbde89c3a9c09464e341 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 17 Feb 2025 09:54:34 +0300 Subject: [PATCH 3/4] Revert second commit --- Modules/clinic/cmathmodule.c.h | 632 ++++----------------------------- Modules/cmathmodule.c | 6 +- 2 files changed, 73 insertions(+), 565 deletions(-) diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h index 61269358c2c883..16eaba7aa7ee39 100644 --- a/Modules/clinic/cmathmodule.c.h +++ b/Modules/clinic/cmathmodule.c.h @@ -6,59 +6,28 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif -#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() +#include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(cmath_acos__doc__, -"acos($module, /, z)\n" +"acos($module, z, /)\n" "--\n" "\n" "Return the arc cosine of z."); #define CMATH_ACOS_METHODDEF \ - {"acos", _PyCFunction_CAST(cmath_acos), METH_FASTCALL|METH_KEYWORDS, cmath_acos__doc__}, + {"acos", (PyCFunction)cmath_acos, METH_O, cmath_acos__doc__}, static Py_complex cmath_acos_impl(PyObject *module, Py_complex z); static PyObject * -cmath_acos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_acos(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "acos", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -82,56 +51,25 @@ cmath_acos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_acosh__doc__, -"acosh($module, /, z)\n" +"acosh($module, z, /)\n" "--\n" "\n" "Return the inverse hyperbolic cosine of z."); #define CMATH_ACOSH_METHODDEF \ - {"acosh", _PyCFunction_CAST(cmath_acosh), METH_FASTCALL|METH_KEYWORDS, cmath_acosh__doc__}, + {"acosh", (PyCFunction)cmath_acosh, METH_O, cmath_acosh__doc__}, static Py_complex cmath_acosh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_acosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_acosh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "acosh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -155,56 +93,25 @@ cmath_acosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } PyDoc_STRVAR(cmath_asin__doc__, -"asin($module, /, z)\n" +"asin($module, z, /)\n" "--\n" "\n" "Return the arc sine of z."); #define CMATH_ASIN_METHODDEF \ - {"asin", _PyCFunction_CAST(cmath_asin), METH_FASTCALL|METH_KEYWORDS, cmath_asin__doc__}, + {"asin", (PyCFunction)cmath_asin, METH_O, cmath_asin__doc__}, static Py_complex cmath_asin_impl(PyObject *module, Py_complex z); static PyObject * -cmath_asin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_asin(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "asin", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -228,56 +135,25 @@ cmath_asin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_asinh__doc__, -"asinh($module, /, z)\n" +"asinh($module, z, /)\n" "--\n" "\n" "Return the inverse hyperbolic sine of z."); #define CMATH_ASINH_METHODDEF \ - {"asinh", _PyCFunction_CAST(cmath_asinh), METH_FASTCALL|METH_KEYWORDS, cmath_asinh__doc__}, + {"asinh", (PyCFunction)cmath_asinh, METH_O, cmath_asinh__doc__}, static Py_complex cmath_asinh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_asinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_asinh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "asinh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -301,56 +177,25 @@ cmath_asinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } PyDoc_STRVAR(cmath_atan__doc__, -"atan($module, /, z)\n" +"atan($module, z, /)\n" "--\n" "\n" "Return the arc tangent of z."); #define CMATH_ATAN_METHODDEF \ - {"atan", _PyCFunction_CAST(cmath_atan), METH_FASTCALL|METH_KEYWORDS, cmath_atan__doc__}, + {"atan", (PyCFunction)cmath_atan, METH_O, cmath_atan__doc__}, static Py_complex cmath_atan_impl(PyObject *module, Py_complex z); static PyObject * -cmath_atan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_atan(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "atan", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -374,56 +219,25 @@ cmath_atan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_atanh__doc__, -"atanh($module, /, z)\n" +"atanh($module, z, /)\n" "--\n" "\n" "Return the inverse hyperbolic tangent of z."); #define CMATH_ATANH_METHODDEF \ - {"atanh", _PyCFunction_CAST(cmath_atanh), METH_FASTCALL|METH_KEYWORDS, cmath_atanh__doc__}, + {"atanh", (PyCFunction)cmath_atanh, METH_O, cmath_atanh__doc__}, static Py_complex cmath_atanh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_atanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_atanh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "atanh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -447,56 +261,25 @@ cmath_atanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } PyDoc_STRVAR(cmath_cos__doc__, -"cos($module, /, z)\n" +"cos($module, z, /)\n" "--\n" "\n" "Return the cosine of z."); #define CMATH_COS_METHODDEF \ - {"cos", _PyCFunction_CAST(cmath_cos), METH_FASTCALL|METH_KEYWORDS, cmath_cos__doc__}, + {"cos", (PyCFunction)cmath_cos, METH_O, cmath_cos__doc__}, static Py_complex cmath_cos_impl(PyObject *module, Py_complex z); static PyObject * -cmath_cos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_cos(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "cos", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -520,56 +303,25 @@ cmath_cos(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k } PyDoc_STRVAR(cmath_cosh__doc__, -"cosh($module, /, z)\n" +"cosh($module, z, /)\n" "--\n" "\n" "Return the hyperbolic cosine of z."); #define CMATH_COSH_METHODDEF \ - {"cosh", _PyCFunction_CAST(cmath_cosh), METH_FASTCALL|METH_KEYWORDS, cmath_cosh__doc__}, + {"cosh", (PyCFunction)cmath_cosh, METH_O, cmath_cosh__doc__}, static Py_complex cmath_cosh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_cosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_cosh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "cosh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -593,56 +345,25 @@ cmath_cosh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_exp__doc__, -"exp($module, /, z)\n" +"exp($module, z, /)\n" "--\n" "\n" "Return the exponential value e**z."); #define CMATH_EXP_METHODDEF \ - {"exp", _PyCFunction_CAST(cmath_exp), METH_FASTCALL|METH_KEYWORDS, cmath_exp__doc__}, + {"exp", (PyCFunction)cmath_exp, METH_O, cmath_exp__doc__}, static Py_complex cmath_exp_impl(PyObject *module, Py_complex z); static PyObject * -cmath_exp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_exp(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "exp", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -666,56 +387,25 @@ cmath_exp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k } PyDoc_STRVAR(cmath_log10__doc__, -"log10($module, /, z)\n" +"log10($module, z, /)\n" "--\n" "\n" "Return the base-10 logarithm of z."); #define CMATH_LOG10_METHODDEF \ - {"log10", _PyCFunction_CAST(cmath_log10), METH_FASTCALL|METH_KEYWORDS, cmath_log10__doc__}, + {"log10", (PyCFunction)cmath_log10, METH_O, cmath_log10__doc__}, static Py_complex cmath_log10_impl(PyObject *module, Py_complex z); static PyObject * -cmath_log10(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_log10(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "log10", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -739,56 +429,25 @@ cmath_log10(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject } PyDoc_STRVAR(cmath_sin__doc__, -"sin($module, /, z)\n" +"sin($module, z, /)\n" "--\n" "\n" "Return the sine of z."); #define CMATH_SIN_METHODDEF \ - {"sin", _PyCFunction_CAST(cmath_sin), METH_FASTCALL|METH_KEYWORDS, cmath_sin__doc__}, + {"sin", (PyCFunction)cmath_sin, METH_O, cmath_sin__doc__}, static Py_complex cmath_sin_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_sin(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "sin", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -812,56 +471,25 @@ cmath_sin(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k } PyDoc_STRVAR(cmath_sinh__doc__, -"sinh($module, /, z)\n" +"sinh($module, z, /)\n" "--\n" "\n" "Return the hyperbolic sine of z."); #define CMATH_SINH_METHODDEF \ - {"sinh", _PyCFunction_CAST(cmath_sinh), METH_FASTCALL|METH_KEYWORDS, cmath_sinh__doc__}, + {"sinh", (PyCFunction)cmath_sinh, METH_O, cmath_sinh__doc__}, static Py_complex cmath_sinh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_sinh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "sinh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -885,56 +513,25 @@ cmath_sinh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_sqrt__doc__, -"sqrt($module, /, z)\n" +"sqrt($module, z, /)\n" "--\n" "\n" "Return the square root of z."); #define CMATH_SQRT_METHODDEF \ - {"sqrt", _PyCFunction_CAST(cmath_sqrt), METH_FASTCALL|METH_KEYWORDS, cmath_sqrt__doc__}, + {"sqrt", (PyCFunction)cmath_sqrt, METH_O, cmath_sqrt__doc__}, static Py_complex cmath_sqrt_impl(PyObject *module, Py_complex z); static PyObject * -cmath_sqrt(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_sqrt(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "sqrt", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -958,56 +555,25 @@ cmath_sqrt(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_tan__doc__, -"tan($module, /, z)\n" +"tan($module, z, /)\n" "--\n" "\n" "Return the tangent of z."); #define CMATH_TAN_METHODDEF \ - {"tan", _PyCFunction_CAST(cmath_tan), METH_FASTCALL|METH_KEYWORDS, cmath_tan__doc__}, + {"tan", (PyCFunction)cmath_tan, METH_O, cmath_tan__doc__}, static Py_complex cmath_tan_impl(PyObject *module, Py_complex z); static PyObject * -cmath_tan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_tan(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "tan", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -1031,56 +597,25 @@ cmath_tan(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *k } PyDoc_STRVAR(cmath_tanh__doc__, -"tanh($module, /, z)\n" +"tanh($module, z, /)\n" "--\n" "\n" "Return the hyperbolic tangent of z."); #define CMATH_TANH_METHODDEF \ - {"tanh", _PyCFunction_CAST(cmath_tanh), METH_FASTCALL|METH_KEYWORDS, cmath_tanh__doc__}, + {"tanh", (PyCFunction)cmath_tanh, METH_O, cmath_tanh__doc__}, static Py_complex cmath_tanh_impl(PyObject *module, Py_complex z); static PyObject * -cmath_tanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_tanh(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 1 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "tanh", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[1]; Py_complex z; Py_complex _return_value; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { - goto exit; - } - z = PyComplex_AsCComplex(args[0]); + z = PyComplex_AsCComplex(arg); if (PyErr_Occurred()) { goto exit; } @@ -1104,7 +639,7 @@ cmath_tanh(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject * } PyDoc_STRVAR(cmath_log__doc__, -"log($module, /, z, base=)\n" +"log($module, z, base=, /)\n" "--\n" "\n" "log(z[, base]) -> the logarithm of z to the given base.\n" @@ -1112,59 +647,30 @@ PyDoc_STRVAR(cmath_log__doc__, "If the base is not specified, returns the natural logarithm (base e) of z."); #define CMATH_LOG_METHODDEF \ - {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL|METH_KEYWORDS, cmath_log__doc__}, + {"log", _PyCFunction_CAST(cmath_log), METH_FASTCALL, cmath_log__doc__}, static PyObject * cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj); static PyObject * -cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs) { PyObject *return_value = NULL; - #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - - #define NUM_KEYWORDS 2 - static struct { - PyGC_Head _this_is_not_used; - PyObject_VAR_HEAD - PyObject *ob_item[NUM_KEYWORDS]; - } _kwtuple = { - .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) - .ob_item = { _Py_LATIN1_CHR('z'), &_Py_ID(base), }, - }; - #undef NUM_KEYWORDS - #define KWTUPLE (&_kwtuple.ob_base.ob_base) - - #else // !Py_BUILD_CORE - # define KWTUPLE NULL - #endif // !Py_BUILD_CORE - - static const char * const _keywords[] = {"z", "base", NULL}; - static _PyArg_Parser _parser = { - .keywords = _keywords, - .fname = "log", - .kwtuple = KWTUPLE, - }; - #undef KWTUPLE - PyObject *argsbuf[2]; - Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; Py_complex x; PyObject *y_obj = NULL; - args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, - /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); - if (!args) { + if (!_PyArg_CheckPositional("log", nargs, 1, 2)) { goto exit; } x = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } - if (!noptargs) { - goto skip_optional_pos; + if (nargs < 2) { + goto skip_optional; } y_obj = args[1]; -skip_optional_pos: +skip_optional: return_value = cmath_log_impl(module, x, y_obj); exit: @@ -1477,4 +983,4 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=2f80251dbf9d18a3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5fda69f15dc9dfc9 input=a9049054013a1b77]*/ diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index 1f920fa2c28578..81cbf0d554de3c 100644 --- a/Modules/cmathmodule.c +++ b/Modules/cmathmodule.c @@ -169,13 +169,14 @@ static Py_complex acos_special_values[7][7]; cmath.acos -> Py_complex_protected z: Py_complex_protected + / Return the arc cosine of z. [clinic start generated code]*/ static Py_complex cmath_acos_impl(PyObject *module, Py_complex z) -/*[clinic end generated code: output=40bd42853fd460ae input=825ee8128f5c21e2]*/ +/*[clinic end generated code: output=40bd42853fd460ae input=bd6cbd78ae851927]*/ { Py_complex s1, s2, r; @@ -864,6 +865,7 @@ cmath.log z as x: Py_complex base as y_obj: object = NULL + / log(z[, base]) -> the logarithm of z to the given base. @@ -872,7 +874,7 @@ If the base is not specified, returns the natural logarithm (base e) of z. static PyObject * cmath_log_impl(PyObject *module, Py_complex x, PyObject *y_obj) -/*[clinic end generated code: output=4effdb7d258e0d94 input=62e46be565758323]*/ +/*[clinic end generated code: output=4effdb7d258e0d94 input=e1f81d4fcfd26497]*/ { Py_complex y; From ec3754eca73896bf2cd72a84f388c99ed4d5db43 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 17 Feb 2025 14:56:49 +0300 Subject: [PATCH 4/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/cmath.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/cmath.rst b/Doc/library/cmath.rst index 49c4d491a7ea88..31dacae35c7748 100644 --- a/Doc/library/cmath.rst +++ b/Doc/library/cmath.rst @@ -79,7 +79,7 @@ rectangular coordinates to polar coordinates and back. .. function:: polar(z) Return the representation of *z* in polar coordinates. Returns a - pair ``(r, phi)`` where *r* is the modulus of *z* and phi is the + pair ``(r, phi)`` where *r* is the modulus of *z* and *phi* is the phase of *z*. ``polar(z)`` is equivalent to ``(abs(z), phase(z))``. @@ -101,7 +101,7 @@ Power and logarithmic functions .. function:: log(z[, base]) - Returns the logarithm of *z* to the given *base*. If the *base* is not + Return the logarithm of *z* to the given *base*. If the *base* is not specified, returns the natural logarithm of *z*. There is one branch cut, from 0 along the negative real axis to -∞.