Fixed #1593 spacing of the builtin_format function is inconsistent. Thanks to Joseph for the fix

This commit is contained in:
Christian Heimes 2007-12-11 20:20:39 +00:00
parent a3534a6ff5
commit 94b7d3db59
1 changed files with 43 additions and 43 deletions

View File

@ -284,58 +284,58 @@ If the predicate is None, 'lambda x: bool(x)' is assumed.\n\
static PyObject * static PyObject *
builtin_format(PyObject *self, PyObject *args) builtin_format(PyObject *self, PyObject *args)
{ {
static PyObject * format_str = NULL; static PyObject * format_str = NULL;
PyObject *value; PyObject *value;
PyObject *spec = NULL; PyObject *spec = NULL;
PyObject *meth; PyObject *meth;
PyObject *empty = NULL; PyObject *empty = NULL;
PyObject *result = NULL; PyObject *result = NULL;
/* Initialize cached value */ /* Initialize cached value */
if (format_str == NULL) { if (format_str == NULL) {
/* Initialize static variable needed by _PyType_Lookup */ /* Initialize static variable needed by _PyType_Lookup */
format_str = PyUnicode_FromString("__format__"); format_str = PyUnicode_FromString("__format__");
if (format_str == NULL) if (format_str == NULL)
goto done; goto done;
} }
if (!PyArg_ParseTuple(args, "O|U:format", &value, &spec)) if (!PyArg_ParseTuple(args, "O|U:format", &value, &spec))
goto done; goto done;
/* initialize the default value */ /* initialize the default value */
if (spec == NULL) { if (spec == NULL) {
empty = PyUnicode_FromUnicode(NULL, 0); empty = PyUnicode_FromUnicode(NULL, 0);
spec = empty; spec = empty;
} }
/* Make sure the type is initialized. float gets initialized late */ /* Make sure the type is initialized. float gets initialized late */
if (Py_Type(value)->tp_dict == NULL) if (Py_Type(value)->tp_dict == NULL)
if (PyType_Ready(Py_Type(value)) < 0) if (PyType_Ready(Py_Type(value)) < 0)
goto done; goto done;
/* Find the (unbound!) __format__ method (a borrowed reference) */ /* Find the (unbound!) __format__ method (a borrowed reference) */
meth = _PyType_Lookup(Py_Type(value), format_str); meth = _PyType_Lookup(Py_Type(value), format_str);
if (meth == NULL) { if (meth == NULL) {
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Type %.100s doesn't define __format__", "Type %.100s doesn't define __format__",
Py_Type(value)->tp_name); Py_Type(value)->tp_name);
goto done; goto done;
} }
/* And call it, binding it to the value */ /* And call it, binding it to the value */
result = PyObject_CallFunctionObjArgs(meth, value, spec, NULL); result = PyObject_CallFunctionObjArgs(meth, value, spec, NULL);
if (result && !PyUnicode_Check(result)) { if (result && !PyUnicode_Check(result)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"__format__ method did not return string"); "__format__ method did not return string");
Py_DECREF(result); Py_DECREF(result);
result = NULL; result = NULL;
goto done; goto done;
} }
done: done:
Py_XDECREF(empty); Py_XDECREF(empty);
return result; return result;
} }
PyDoc_STRVAR(format_doc, PyDoc_STRVAR(format_doc,