Mercurial > cpython-lru_cache-weakref
diff Objects/complexobject.c @ 53632:2cde0d003ffc
Issue #1588: Add complex.__format__.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Thu, 30 Apr 2009 01:00:33 +0000 |
| parents | 7835ada3cda2 |
| children | 13a82a710f19 |
line wrap: on
line diff
--- a/Objects/complexobject.c Thu Apr 30 00:59:58 2009 +0000 +++ b/Objects/complexobject.c Thu Apr 30 01:00:33 2009 +0000 @@ -681,6 +681,23 @@ 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 @@ complex_is_finite_doc}, #endif {"__getnewargs__", (PyCFunction)complex_getnewargs, METH_NOARGS}, + {"__format__", (PyCFunction)complex__format__, + METH_VARARGS, complex__format__doc}, {NULL, NULL} /* sentinel */ };
