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)); 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;