diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2020-07-20 21:53:29 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-20 15:53:29 +0300 |
commit | e123012d79121ab543583631bb84c7fc27d06338 (patch) | |
tree | b6f771ad05a25d45c261c0dbbb61786f548ce6dd /Objects | |
parent | bpo-41336: Fix the error handling in zoneinfo_new_instance() (GH-21546) (diff) | |
download | cpython-e123012d79121ab543583631bb84c7fc27d06338.tar.gz cpython-e123012d79121ab543583631bb84c7fc27d06338.tar.bz2 cpython-e123012d79121ab543583631bb84c7fc27d06338.zip |
bpo-41343: Convert methods of complex to Argument Clinic (GH-21550)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/clinic/complexobject.c.h | 69 | ||||
-rw-r--r-- | Objects/complexobject.c | 56 |
2 files changed, 99 insertions, 26 deletions
diff --git a/Objects/clinic/complexobject.c.h b/Objects/clinic/complexobject.c.h index 8caa910d037..4c8191fa831 100644 --- a/Objects/clinic/complexobject.c.h +++ b/Objects/clinic/complexobject.c.h @@ -2,6 +2,73 @@ preserve [clinic start generated code]*/ +PyDoc_STRVAR(complex_conjugate__doc__, +"conjugate($self, /)\n" +"--\n" +"\n" +"Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); + +#define COMPLEX_CONJUGATE_METHODDEF \ + {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS, complex_conjugate__doc__}, + +static PyObject * +complex_conjugate_impl(PyComplexObject *self); + +static PyObject * +complex_conjugate(PyComplexObject *self, PyObject *Py_UNUSED(ignored)) +{ + return complex_conjugate_impl(self); +} + +PyDoc_STRVAR(complex___getnewargs____doc__, +"__getnewargs__($self, /)\n" +"--\n" +"\n"); + +#define COMPLEX___GETNEWARGS___METHODDEF \ + {"__getnewargs__", (PyCFunction)complex___getnewargs__, METH_NOARGS, complex___getnewargs____doc__}, + +static PyObject * +complex___getnewargs___impl(PyComplexObject *self); + +static PyObject * +complex___getnewargs__(PyComplexObject *self, PyObject *Py_UNUSED(ignored)) +{ + return complex___getnewargs___impl(self); +} + +PyDoc_STRVAR(complex___format____doc__, +"__format__($self, format_spec, /)\n" +"--\n" +"\n" +"Convert to a string according to format_spec."); + +#define COMPLEX___FORMAT___METHODDEF \ + {"__format__", (PyCFunction)complex___format__, METH_O, complex___format____doc__}, + +static PyObject * +complex___format___impl(PyComplexObject *self, PyObject *format_spec); + +static PyObject * +complex___format__(PyComplexObject *self, PyObject *arg) +{ + PyObject *return_value = NULL; + PyObject *format_spec; + + if (!PyUnicode_Check(arg)) { + _PyArg_BadArgument("__format__", "argument", "str", arg); + goto exit; + } + if (PyUnicode_READY(arg) == -1) { + goto exit; + } + format_spec = arg; + return_value = complex___format___impl(self, format_spec); + +exit: + return return_value; +} + PyDoc_STRVAR(complex_new__doc__, "complex(real=0, imag=0)\n" "--\n" @@ -46,4 +113,4 @@ skip_optional_pos: exit: return return_value; } -/*[clinic end generated code: output=a0fe23fdbdc9b06b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=193a37aebaaa5f89 input=a9049054013a1b77]*/ diff --git a/Objects/complexobject.c b/Objects/complexobject.c index d983a30901d..69f6c17b4a4 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -684,46 +684,54 @@ complex_float(PyObject *v) return NULL; } +/*[clinic input] +complex.conjugate + +Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j. +[clinic start generated code]*/ + static PyObject * -complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) +complex_conjugate_impl(PyComplexObject *self) +/*[clinic end generated code: output=5059ef162edfc68e input=5fea33e9747ec2c4]*/ { - Py_complex c; - c = ((PyComplexObject *)self)->cval; + Py_complex c = self->cval; c.imag = -c.imag; return PyComplex_FromCComplex(c); } -PyDoc_STRVAR(complex_conjugate_doc, -"complex.conjugate() -> complex\n" -"\n" -"Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j."); +/*[clinic input] +complex.__getnewargs__ + +[clinic start generated code]*/ static PyObject * -complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored)) +complex___getnewargs___impl(PyComplexObject *self) +/*[clinic end generated code: output=689b8206e8728934 input=539543e0a50533d7]*/ { - Py_complex c = v->cval; + Py_complex c = self->cval; return Py_BuildValue("(dd)", c.real, c.imag); } -PyDoc_STRVAR(complex__format__doc, -"complex.__format__() -> str\n" -"\n" -"Convert to a string according to format_spec."); + +/*[clinic input] +complex.__format__ + + format_spec: unicode + / + +Convert to a string according to format_spec. +[clinic start generated code]*/ static PyObject * -complex__format__(PyObject* self, PyObject* args) +complex___format___impl(PyComplexObject *self, PyObject *format_spec) +/*[clinic end generated code: output=bfcb60df24cafea0 input=014ef5488acbe1d5]*/ { - PyObject *format_spec; _PyUnicodeWriter writer; int ret; - - if (!PyArg_ParseTuple(args, "U:__format__", &format_spec)) - return NULL; - _PyUnicodeWriter_Init(&writer); ret = _PyComplex_FormatAdvancedWriter( &writer, - self, + (PyObject *)self, format_spec, 0, PyUnicode_GET_LENGTH(format_spec)); if (ret == -1) { _PyUnicodeWriter_Dealloc(&writer); @@ -733,11 +741,9 @@ complex__format__(PyObject* self, PyObject* args) } static PyMethodDef complex_methods[] = { - {"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS, - complex_conjugate_doc}, - {"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS}, - {"__format__", (PyCFunction)complex__format__, - METH_VARARGS, complex__format__doc}, + COMPLEX_CONJUGATE_METHODDEF + COMPLEX___GETNEWARGS___METHODDEF + COMPLEX___FORMAT___METHODDEF {NULL, NULL} /* sentinel */ }; |