mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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.
This commit is contained in:
parent
e4dc324884
commit
8c66326368
22 changed files with 2669 additions and 18 deletions
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include "Python.h"
|
||||
|
||||
#include "formatter_unicode.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#if !defined(__STDC__)
|
||||
|
|
@ -1015,6 +1017,21 @@ float_getzero(PyObject *v, void *closure)
|
|||
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 @@ static PyMethodDef float_methods[] = {
|
|||
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 */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue