Mercurial > cpython-lru_cache-weakref
diff Objects/floatobject.c @ 42817:5355337709e1
Implementation of PEP 3101, Advanced String Formatting.
Known issues:
The string.Formatter class, as discussed in the PEP, is incomplete.
Error handling needs to conform to the PEP.
Need to fix this warning that I introduced in Python/formatter_unicode.c:
Objects/stringlib/unicodedefs.h:26: warning: `STRINGLIB_CMP' defined but not used
Need to make sure sign formatting is correct, more tests needed.
Need to remove '()' sign formatting, left over from an earlier version of the PEP.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Sat, 25 Aug 2007 02:26:07 +0000 |
| parents | 077fe7860cc9 |
| children | 824b9d52e006 |
line wrap: on
line diff
--- a/Objects/floatobject.c Sat Aug 25 01:33:49 2007 +0000 +++ b/Objects/floatobject.c Sat Aug 25 02:26:07 2007 +0000 @@ -6,6 +6,8 @@ #include "Python.h" +#include "formatter_unicode.h" + #include <ctype.h> #if !defined(__STDC__) @@ -1015,6 +1017,21 @@ return PyFloat_FromDouble(0.0); } +static PyObject * +float__format__(PyObject *self, PyObject *args) +{ + /* when back porting this to 2.6, check type of the format_spec + and call either unicode_long__format__ or + string_long__format__ */ + return unicode_float__format__(self, args); +} + +PyDoc_STRVAR(float__format__doc, +"float.__format__(format_spec) -> string\n" +"\n" +"Formats the float according to format_spec."); + + static PyMethodDef float_methods[] = { {"conjugate", (PyCFunction)float_float, METH_NOARGS, "Returns self, the complex conjugate of any float."}, @@ -1028,6 +1045,8 @@ METH_O|METH_CLASS, float_getformat_doc}, {"__setformat__", (PyCFunction)float_setformat, METH_VARARGS|METH_CLASS, float_setformat_doc}, + {"__format__", (PyCFunction)float__format__, + METH_VARARGS, float__format__doc}, {NULL, NULL} /* sentinel */ };
