Skip to content

Commit 6a2431f

Browse files
corona10Seth Sims
authored andcommitted
bpo-41343: Convert methods of complex to Argument Clinic (pythonGH-21550)
1 parent afb73ff commit 6a2431f

File tree

2 files changed

+99
-26
lines changed

2 files changed

+99
-26
lines changed

Objects/clinic/complexobject.c.h

Lines changed: 68 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: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -684,46 +684,54 @@ complex_float(PyObject *v)
684684
return NULL;
685685
}
686686

687+
/*[clinic input]
688+
complex.conjugate
689+
690+
Return the complex conjugate of its argument. (3-4j).conjugate() == 3+4j.
691+
[clinic start generated code]*/
692+
687693
static PyObject *
688-
complex_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
694+
complex_conjugate_impl(PyComplexObject *self)
695+
/*[clinic end generated code: output=5059ef162edfc68e input=5fea33e9747ec2c4]*/
689696
{
690-
Py_complex c;
691-
c = ((PyComplexObject *)self)->cval;
697+
Py_complex c = self->cval;
692698
c.imag = -c.imag;
693699
return PyComplex_FromCComplex(c);
694700
}
695701

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.");
702+
/*[clinic input]
703+
complex.__getnewargs__
704+
705+
[clinic start generated code]*/
700706

701707
static PyObject *
702-
complex_getnewargs(PyComplexObject *v, PyObject *Py_UNUSED(ignored))
708+
complex___getnewargs___impl(PyComplexObject *self)
709+
/*[clinic end generated code: output=689b8206e8728934 input=539543e0a50533d7]*/
703710
{
704-
Py_complex c = v->cval;
711+
Py_complex c = self->cval;
705712
return Py_BuildValue("(dd)", c.real, c.imag);
706713
}
707714

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

713725
static PyObject *
714-
complex__format__(PyObject* self, PyObject* args)
726+
complex___format___impl(PyComplexObject *self, PyObject *format_spec)
727+
/*[clinic end generated code: output=bfcb60df24cafea0 input=014ef5488acbe1d5]*/
715728
{
716-
PyObject *format_spec;
717729
_PyUnicodeWriter writer;
718730
int ret;
719-
720-
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
721-
return NULL;
722-
723731
_PyUnicodeWriter_Init(&writer);
724732
ret = _PyComplex_FormatAdvancedWriter(
725733
&writer,
726-
self,
734+
(PyObject *)self,
727735
format_spec, 0, PyUnicode_GET_LENGTH(format_spec));
728736
if (ret == -1) {
729737
_PyUnicodeWriter_Dealloc(&writer);
@@ -733,11 +741,9 @@ complex__format__(PyObject* self, PyObject* args)
733741
}
734742

735743
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},
744+
COMPLEX_CONJUGATE_METHODDEF
745+
COMPLEX___GETNEWARGS___METHODDEF
746+
COMPLEX___FORMAT___METHODDEF
741747
{NULL, NULL} /* sentinel */
742748
};
743749

0 commit comments

Comments
 (0)