Mercurial > cpython-lru_cache-weakref
diff Objects/stringlib/formatter.h @ 66444:eded691497b7
Issue #7094: Add alternate ('#') flag to __format__ methods for float, complex and Decimal. Allows greater control over when decimal points appear. Added to make transitioning from %-formatting easier. '#g' still has a problem with Decimal which I'll fix soon.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Thu, 25 Nov 2010 16:08:06 +0000 |
| parents | eafe07d40eb7 |
| children | 3c9232a684ae |
line wrap: on
line diff
--- a/Objects/stringlib/formatter.h Thu Nov 25 14:56:44 2010 +0000 +++ b/Objects/stringlib/formatter.h Thu Nov 25 16:08:06 2010 +0000 @@ -941,13 +941,8 @@ from a hard-code pseudo-locale */ LocaleInfo locale; - /* Alternate is not allowed on floats. */ - if (format->alternate) { - PyErr_SetString(PyExc_ValueError, - "Alternate form (#) not allowed in float format " - "specifier"); - goto done; - } + if (format->alternate) + flags |= Py_DTSF_ALT; if (type == '\0') { /* Omitted type specifier. Behaves in the same way as repr(x) @@ -1104,15 +1099,7 @@ from a hard-code pseudo-locale */ LocaleInfo locale; - /* Alternate is not allowed on complex. */ - if (format->alternate) { - PyErr_SetString(PyExc_ValueError, - "Alternate form (#) not allowed in complex format " - "specifier"); - goto done; - } - - /* Neither is zero pading. */ + /* Zero padding is not allowed. */ if (format->fill_char == '0') { PyErr_SetString(PyExc_ValueError, "Zero padding is not allowed in complex format " @@ -1135,6 +1122,9 @@ if (im == -1.0 && PyErr_Occurred()) goto done; + if (format->alternate) + flags |= Py_DTSF_ALT; + if (type == '\0') { /* Omitted type specifier. Should be like str(self). */ type = 'r';
