mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Issue #1588: Add complex.__format__.
This commit is contained in:
parent
738a41dd85
commit
58a42244cf
6 changed files with 425 additions and 52 deletions
|
@ -681,6 +681,23 @@ complex_getnewargs(PyComplexObject *v)
|
|||
return Py_BuildValue("(dd)", c.real, c.imag);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(complex__format__doc,
|
||||
"complex.__format__() -> str\n"
|
||||
"\n"
|
||||
"Converts to a string according to format_spec.");
|
||||
|
||||
static PyObject *
|
||||
complex__format__(PyObject* self, PyObject* args)
|
||||
{
|
||||
PyObject *format_spec;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
|
||||
return NULL;
|
||||
return _PyComplex_FormatAdvanced(self,
|
||||
PyUnicode_AS_UNICODE(format_spec),
|
||||
PyUnicode_GET_SIZE(format_spec));
|
||||
}
|
||||
|
||||
#if 0
|
||||
static PyObject *
|
||||
complex_is_finite(PyObject *self)
|
||||
|
@ -705,6 +722,8 @@ static PyMethodDef complex_methods[] = {
|
|||
complex_is_finite_doc},
|
||||
#endif
|
||||
{"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS},
|
||||
{"__format__", (PyCFunction)complex__format__,
|
||||
METH_VARARGS, complex__format__doc},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue