mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
bpo-24234: implement complex.__complex__ (GH-27887)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
parent
eec340ea3a
commit
6082bb5add
6 changed files with 57 additions and 3 deletions
|
|
@ -693,8 +693,29 @@ complex___format___impl(PyComplexObject *self, PyObject *format_spec)
|
|||
return _PyUnicodeWriter_Finish(&writer);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
complex.__complex__
|
||||
|
||||
Convert this value to exact type complex.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
complex___complex___impl(PyComplexObject *self)
|
||||
/*[clinic end generated code: output=e6b35ba3d275dc9c input=3589ada9d27db854]*/
|
||||
{
|
||||
if (PyComplex_CheckExact(self)) {
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
else {
|
||||
return PyComplex_FromCComplex(self->cval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef complex_methods[] = {
|
||||
COMPLEX_CONJUGATE_METHODDEF
|
||||
COMPLEX___COMPLEX___METHODDEF
|
||||
COMPLEX___GETNEWARGS___METHODDEF
|
||||
COMPLEX___FORMAT___METHODDEF
|
||||
{NULL, NULL} /* sentinel */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue