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/6] 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/6] + 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/6] 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/6] 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 -∞. From 6548be004a9cc380a69a586d9e3596054a027b56 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 30 Mar 2025 06:21:57 +0300 Subject: [PATCH 5/6] gh-131885: simplify function signatures in the cmath module Now function docstrings are in sync with the module docs, for example: ```pycon >>> import cmath, inspect >>> help(cmath.sin) Help on built-in function sin in module cmath: sin(z) Return the sine of z. >>> inspect.signature(cmath.sin) ``` As a side effect, this allows `sin(z=1.23)` calls. The price is slight performance penalty (maybe this can be fixed on AC side): | Benchmark | ref | patch | |----------------|:------:|:--------------------:| | sin(1.1) | 417 ns | 428 ns: 1.03x slower | | sin(1j) | 414 ns | 422 ns: 1.02x slower | | log(2.3) | 390 ns | 409 ns: 1.05x slower | | log(1+2j) | 449 ns | 468 ns: 1.04x slower | | log(2.1, 3.2) | 601 ns | 630 ns: 1.05x slower | | Geometric mean | (ref) | 1.04x slower | --- ...-03-30-06-42-09.gh-issue-131885.KrgcBT.rst | 2 + Modules/clinic/cmathmodule.c.h | 931 ++++++++++++++++-- Modules/cmathmodule.c | 19 +- 3 files changed, 834 insertions(+), 118 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-03-30-06-42-09.gh-issue-131885.KrgcBT.rst diff --git a/Misc/NEWS.d/next/Library/2025-03-30-06-42-09.gh-issue-131885.KrgcBT.rst b/Misc/NEWS.d/next/Library/2025-03-30-06-42-09.gh-issue-131885.KrgcBT.rst new file mode 100644 index 00000000000000..899c6af0b74784 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-30-06-42-09.gh-issue-131885.KrgcBT.rst @@ -0,0 +1,2 @@ +Simplify function signatures in the :mod:`cmath` module, e.g. ``sin(z)`` +instead of ``sin(z, /)``. Patch by Sergey B Kirpichev. diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h index 7f9e65baf120ea..560f0a1f2bfc68 100644 --- a/Modules/clinic/cmathmodule.c.h +++ b/Modules/clinic/cmathmodule.c.h @@ -6,28 +6,61 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -51,25 +84,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -93,25 +159,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -135,25 +234,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -177,25 +309,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -219,25 +384,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -261,25 +459,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -303,25 +534,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -345,25 +609,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -387,35 +684,68 @@ 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; - Py_complex z; - Py_complex _return_value; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - z = PyComplex_AsCComplex(arg); - if (PyErr_Occurred()) { - goto exit; - } - /* modifications for z */ - errno = 0; - _return_value = cmath_log10_impl(module, z); - if (errno == EDOM) { - PyErr_SetString(PyExc_ValueError, "math domain error"); - goto exit; - } + #define NUM_KEYWORDS 1 + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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]); + if (PyErr_Occurred()) { + goto exit; + } + /* modifications for z */ + errno = 0; + _return_value = cmath_log10_impl(module, z); + if (errno == EDOM) { + PyErr_SetString(PyExc_ValueError, "math domain error"); + goto exit; + } else if (errno == ERANGE) { PyErr_SetString(PyExc_OverflowError, "math range error"); goto exit; @@ -429,25 +759,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -471,25 +834,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -513,25 +909,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -555,25 +984,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -597,25 +1059,58 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { + goto exit; + } + z = PyComplex_AsCComplex(args[0]); if (PyErr_Occurred()) { goto exit; } @@ -639,7 +1134,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 +1142,61 @@ 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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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, + /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 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: @@ -678,24 +1204,57 @@ cmath_log(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(cmath_phase__doc__, -"phase($module, z, /)\n" +"phase($module, /, z)\n" "--\n" "\n" "Return argument, also known as the phase angle, of a complex."); #define CMATH_PHASE_METHODDEF \ - {"phase", (PyCFunction)cmath_phase, METH_O, cmath_phase__doc__}, + {"phase", _PyCFunction_CAST(cmath_phase), METH_FASTCALL|METH_KEYWORDS, cmath_phase__doc__}, static PyObject * cmath_phase_impl(PyObject *module, Py_complex z); static PyObject * -cmath_phase(PyObject *module, PyObject *arg) +cmath_phase(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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 = "phase", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; - z = PyComplex_AsCComplex(arg); + 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]); if (PyErr_Occurred()) { goto exit; } @@ -706,7 +1265,7 @@ cmath_phase(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_polar__doc__, -"polar($module, z, /)\n" +"polar($module, /, z)\n" "--\n" "\n" "Convert a complex from rectangular coordinates to polar coordinates.\n" @@ -714,18 +1273,51 @@ PyDoc_STRVAR(cmath_polar__doc__, "r is the distance from 0 and phi the phase angle."); #define CMATH_POLAR_METHODDEF \ - {"polar", (PyCFunction)cmath_polar, METH_O, cmath_polar__doc__}, + {"polar", _PyCFunction_CAST(cmath_polar), METH_FASTCALL|METH_KEYWORDS, cmath_polar__doc__}, static PyObject * cmath_polar_impl(PyObject *module, Py_complex z); static PyObject * -cmath_polar(PyObject *module, PyObject *arg) +cmath_polar(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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 = "polar", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; - z = PyComplex_AsCComplex(arg); + 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]); if (PyErr_Occurred()) { goto exit; } @@ -736,25 +1328,55 @@ cmath_polar(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_rect__doc__, -"rect($module, r, phi, /)\n" +"rect($module, /, r, phi)\n" "--\n" "\n" "Convert from polar coordinates to rectangular coordinates."); #define CMATH_RECT_METHODDEF \ - {"rect", _PyCFunction_CAST(cmath_rect), METH_FASTCALL, cmath_rect__doc__}, + {"rect", _PyCFunction_CAST(cmath_rect), METH_FASTCALL|METH_KEYWORDS, cmath_rect__doc__}, static PyObject * cmath_rect_impl(PyObject *module, double r, double phi); static PyObject * -cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs) +cmath_rect(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .ob_item = { _Py_LATIN1_CHR('r'), &_Py_ID(phi), }, + }; + #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[] = {"r", "phi", NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "rect", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[2]; double r; double phi; - if (!_PyArg_CheckPositional("rect", nargs, 2, 2)) { + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, + /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); + if (!args) { goto exit; } if (PyFloat_CheckExact(args[0])) { @@ -784,24 +1406,57 @@ cmath_rect(PyObject *module, PyObject *const *args, Py_ssize_t nargs) } PyDoc_STRVAR(cmath_isfinite__doc__, -"isfinite($module, z, /)\n" +"isfinite($module, /, z)\n" "--\n" "\n" "Return True if both the real and imaginary parts of z are finite, else False."); #define CMATH_ISFINITE_METHODDEF \ - {"isfinite", (PyCFunction)cmath_isfinite, METH_O, cmath_isfinite__doc__}, + {"isfinite", _PyCFunction_CAST(cmath_isfinite), METH_FASTCALL|METH_KEYWORDS, cmath_isfinite__doc__}, static PyObject * cmath_isfinite_impl(PyObject *module, Py_complex z); static PyObject * -cmath_isfinite(PyObject *module, PyObject *arg) +cmath_isfinite(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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 = "isfinite", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; - z = PyComplex_AsCComplex(arg); + 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]); if (PyErr_Occurred()) { goto exit; } @@ -812,24 +1467,57 @@ cmath_isfinite(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_isnan__doc__, -"isnan($module, z, /)\n" +"isnan($module, /, z)\n" "--\n" "\n" "Checks if the real or imaginary part of z not a number (NaN)."); #define CMATH_ISNAN_METHODDEF \ - {"isnan", (PyCFunction)cmath_isnan, METH_O, cmath_isnan__doc__}, + {"isnan", _PyCFunction_CAST(cmath_isnan), METH_FASTCALL|METH_KEYWORDS, cmath_isnan__doc__}, static PyObject * cmath_isnan_impl(PyObject *module, Py_complex z); static PyObject * -cmath_isnan(PyObject *module, PyObject *arg) +cmath_isnan(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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 = "isnan", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; - z = PyComplex_AsCComplex(arg); + 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]); if (PyErr_Occurred()) { goto exit; } @@ -840,24 +1528,57 @@ cmath_isnan(PyObject *module, PyObject *arg) } PyDoc_STRVAR(cmath_isinf__doc__, -"isinf($module, z, /)\n" +"isinf($module, /, z)\n" "--\n" "\n" "Checks if the real or imaginary part of z is infinite."); #define CMATH_ISINF_METHODDEF \ - {"isinf", (PyCFunction)cmath_isinf, METH_O, cmath_isinf__doc__}, + {"isinf", _PyCFunction_CAST(cmath_isinf), METH_FASTCALL|METH_KEYWORDS, cmath_isinf__doc__}, static PyObject * cmath_isinf_impl(PyObject *module, Py_complex z); static PyObject * -cmath_isinf(PyObject *module, PyObject *arg) +cmath_isinf(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 + Py_hash_t ob_hash; + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_hash = -1, + .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 = "isinf", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; Py_complex z; - z = PyComplex_AsCComplex(arg); + 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]); if (PyErr_Occurred()) { goto exit; } @@ -985,4 +1706,4 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec exit: return return_value; } -/*[clinic end generated code: output=631db17fb1c79d66 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7d8406a3c4a0c3e7 input=a9049054013a1b77]*/ diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c index 81cbf0d554de3c..bc4a9c9396e354 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; @@ -913,14 +911,13 @@ math_error(void) cmath.phase z: Py_complex - / Return argument, also known as the phase angle, of a complex. [clinic start generated code]*/ static PyObject * cmath_phase_impl(PyObject *module, Py_complex z) -/*[clinic end generated code: output=50725086a7bfd253 input=5cf75228ba94b69d]*/ +/*[clinic end generated code: output=50725086a7bfd253 input=3ffcb1a685836dea]*/ { double phi; @@ -933,10 +930,7 @@ cmath_phase_impl(PyObject *module, Py_complex z) } /*[clinic input] -cmath.polar - - z: Py_complex - / +cmath.polar = cmath.phase Convert a complex from rectangular coordinates to polar coordinates. @@ -945,7 +939,7 @@ r is the distance from 0 and phi the phase angle. static PyObject * cmath_polar_impl(PyObject *module, Py_complex z) -/*[clinic end generated code: output=d0a8147c41dbb654 input=26c353574fd1a861]*/ +/*[clinic end generated code: output=d0a8147c41dbb654 input=4dabce97b098e272]*/ { double r, phi; @@ -976,14 +970,13 @@ cmath.rect r: double phi: double - / Convert from polar coordinates to rectangular coordinates. [clinic start generated code]*/ static PyObject * cmath_rect_impl(PyObject *module, double r, double phi) -/*[clinic end generated code: output=385a0690925df2d5 input=24c5646d147efd69]*/ +/*[clinic end generated code: output=385a0690925df2d5 input=8c5ac8c4d3f2f69a]*/ { Py_complex z; errno = 0; From 26085bb7c3e8fb541149853abd3304683a0ea7ad Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 30 Mar 2025 07:03:35 +0300 Subject: [PATCH 6/6] + make regen-all --- Include/internal/pycore_global_objects_fini_generated.h | 1 + Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init_generated.h | 1 + Include/internal/pycore_unicodeobject_generated.h | 4 ++++ 4 files changed, 7 insertions(+) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index 605c9e1c480c6e..4175ebd1529390 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -1151,6 +1151,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(persistent_id)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(persistent_load)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(person)); + _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(phi)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(pi_factory)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(pid)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(policy)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 76bc00cfaecf9b..ea996de247f89b 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -642,6 +642,7 @@ struct _Py_global_strings { STRUCT_FOR_ID(persistent_id) STRUCT_FOR_ID(persistent_load) STRUCT_FOR_ID(person) + STRUCT_FOR_ID(phi) STRUCT_FOR_ID(pi_factory) STRUCT_FOR_ID(pid) STRUCT_FOR_ID(policy) diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index 3927cb8adf14c5..c8cd03accdeca4 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -1149,6 +1149,7 @@ extern "C" { INIT_ID(persistent_id), \ INIT_ID(persistent_load), \ INIT_ID(person), \ + INIT_ID(phi), \ INIT_ID(pi_factory), \ INIT_ID(pid), \ INIT_ID(policy), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index 67c71986410eef..0ea079221ec271 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -2356,6 +2356,10 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1)); assert(PyUnicode_GET_LENGTH(string) != 1); + string = &_Py_ID(phi); + _PyUnicode_InternStatic(interp, &string); + assert(_PyUnicode_CheckConsistency(string, 1)); + assert(PyUnicode_GET_LENGTH(string) != 1); string = &_Py_ID(pi_factory); _PyUnicode_InternStatic(interp, &string); assert(_PyUnicode_CheckConsistency(string, 1));