summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2010-11-25 16:08:06 (GMT)
committerEric Smith <eric@trueblade.com>2010-11-25 16:08:06 (GMT)
commit984bb58000df9cdba438c7ecb0bae5ad67878696 (patch)
tree87077ab2bbe949b5241ed9db5f2073572094ffde /Objects/stringlib
parentc1d98d685032dd831ced32463b3f88cce6af4067 (diff)
downloadcpython-984bb58000df9cdba438c7ecb0bae5ad67878696.zip
cpython-984bb58000df9cdba438c7ecb0bae5ad67878696.tar.gz
cpython-984bb58000df9cdba438c7ecb0bae5ad67878696.tar.bz2
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.
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/formatter.h22
1 files changed, 6 insertions, 16 deletions
diff --git a/Objects/stringlib/formatter.h b/Objects/stringlib/formatter.h
index 4fdab06..4fdc62d 100644
--- a/Objects/stringlib/formatter.h
+++ b/Objects/stringlib/formatter.h
@@ -941,13 +941,8 @@ format_float_internal(PyObject *value,
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 @@ format_complex_internal(PyObject *value,
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 @@ format_complex_internal(PyObject *value,
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';