Skip to content

Commit d6098e4

Browse files
committed
bpo-41343: Convert methods of complex to Argument Clinic
1 parent 10e4664 commit d6098e4

File tree

3 files changed

+109
-26
lines changed

3 files changed

+109
-26
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Convert methods of :class:`complex` to Argument Clinic. Patch by Dong-hee
2+
Na.

Objects/clinic/complexobject.c.h

Lines changed: 72 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/complexobject.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -684,46 +684,58 @@ complex_float(PyObject *v)
684684
return NULL;
685685
}
686686

687+
/*[clinic input]
688+
complex.conjugate
689+
690+
complex.conjugate() -> complex
691+
692+
Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.
693+
[clinic start generated code]*/
694+
687695
static PyObject *
688-
complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
696+
complex_conjugate_impl(PyComplexObject *self)
697+
/*[clinic end generated code: output=5059ef162edfc68e input=1d8257f99c298f70]*/
689698
{
690-
Py_complex c;
691-
c = ((PyComplexObject *)self)->cval;
699+
Py_complex c = self->cval;
692700
c.imag = -c.imag;
693701
return PyComplex_FromCComplex(c);
694702
}
695703

696-
PyDoc_STRVAR(complex_conjugate_doc,
697-
"complex.conjugate() -> complex\n"
698-
"\n"
699-
"Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.");
704+
/*[clinic input]
705+
complex.__getnewargs__
706+
707+
[clinic start generated code]*/
700708

701709
static PyObject *
702-
complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored))
710+
complex___getnewargs___impl(PyComplexObject *self)
711+
/*[clinic end generated code: output=689b8206e8728934 input=539543e0a50533d7]*/
703712
{
704-
Py_complex c = v->cval;
713+
Py_complex c = self->cval;
705714
return Py_BuildValue("(dd)", c.real, c.imag);
706715
}
707716

708-
PyDoc_STRVAR(complex__format__doc,
709-
"complex.__format__() -> str\n"
710-
"\n"
711-
"Convert to a string according to format_spec.");
717+
718+
/*[clinic input]
719+
complex.__format__
720+
721+
format_spec: unicode
722+
/
723+
724+
complex.__format__() -> str
725+
726+
Convert to a string according to format_spec.
727+
[clinic start generated code]*/
712728

713729
static PyObject *
714-
complex__format__(PyObject* self, PyObject* args)
730+
complex___format___impl(PyComplexObject *self, PyObject *format_spec)
731+
/*[clinic end generated code: output=bfcb60df24cafea0 input=b62fc6fbc2ec61a5]*/
715732
{
716-
PyObject *format_spec;
717733
_PyUnicodeWriter writer;
718734
int ret;
719-
720-
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
721-
return NULL;
722-
723735
_PyUnicodeWriter_Init(&writer);
724736
ret = _PyComplex_FormatAdvancedWriter(
725737
&writer,
726-
self,
738+
(PyObject *)self,
727739
format_spec, 0, PyUnicode_GET_LENGTH(format_spec));
728740
if (ret == -1) {
729741
_PyUnicodeWriter_Dealloc(&writer);
@@ -733,11 +745,9 @@ complex__format__(PyObject* self, PyObject* args)
733745
}
734746

735747
static PyMethodDef complex_methods[] = {
736-
{"conjugate", (PyCFunction)complex_conjugate, METH_NOARGS,
737-
complex_conjugate_doc},
738-
{"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS},
739-
{"__format__", (PyCFunction)complex__format__,
740-
METH_VARARGS, complex__format__doc},
748+
COMPLEX_CONJUGATE_METHODDEF
749+
COMPLEX___GETNEWARGS___METHODDEF
750+
COMPLEX___FORMAT___METHODDEF
741751
{NULL, NULL} /* sentinel */
742752
};
743753

0 commit comments

Comments
 (0)