1398
1395
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
1400
if (PyString_Check(format_spec))
1401
return string_float__format__(self, args);
1397
if (PyBytes_Check(format_spec))
1398
return _PyFloat_FormatAdvanced(self,
1399
PyBytes_AS_STRING(format_spec),
1400
PyBytes_GET_SIZE(format_spec));
1402
1401
if (PyUnicode_Check(format_spec)) {
1403
1402
/* Convert format_spec to a str */
1404
PyObject *result = NULL;
1405
PyObject *newargs = NULL;
1406
PyObject *string_format_spec = NULL;
1408
string_format_spec = PyObject_Str(format_spec);
1409
if (string_format_spec == NULL)
1412
newargs = Py_BuildValue("(O)", string_format_spec);
1413
if (newargs == NULL)
1416
result = string_float__format__(self, newargs);
1419
Py_XDECREF(string_format_spec);
1420
Py_XDECREF(newargs);
1404
PyObject *str_spec = PyObject_Str(format_spec);
1406
if (str_spec == NULL)
1409
result = _PyFloat_FormatAdvanced(self,
1410
PyBytes_AS_STRING(str_spec),
1411
PyBytes_GET_SIZE(str_spec));
1413
Py_DECREF(str_spec);
1423
1416
PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");