diff options
author | Eric Smith <eric@trueblade.com> | 2009-04-30 01:00:33 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2009-04-30 01:00:33 (GMT) |
commit | 58a42244cfefc96b7adada5344b231ff2f32a86a (patch) | |
tree | a2a90372b3bef2cc1c06bb9f07b880f2c3997731 /Objects/complexobject.c | |
parent | 738a41dd85f55f49508be62a135f9e65b5c92255 (diff) | |
download | cpython-58a42244cfefc96b7adada5344b231ff2f32a86a.zip cpython-58a42244cfefc96b7adada5344b231ff2f32a86a.tar.gz cpython-58a42244cfefc96b7adada5344b231ff2f32a86a.tar.bz2 |
Issue #1588: Add complex.__format__.
Diffstat (limited to 'Objects/complexobject.c')
-rw-r--r-- | Objects/complexobject.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index acd885b..691809f 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -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 */ }; |