diff options
| author | Eric V. Smith <eric@trueblade.com> | 2014-04-15 22:37:55 -0400 |
|---|---|---|
| committer | Eric V. Smith <eric@trueblade.com> | 2014-04-15 22:37:55 -0400 |
| commit | a12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98 (patch) | |
| tree | 3d395e27f831e78b5e9831ea1e855d4e125c303d | |
| parent | 15b04eb42902f84fa3e35387b0c7c3391a204f65 (diff) | |
| download | cpython-git-a12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98.tar.gz | |
Close issue #8931: Make alternate formatting for 'c' raise an exception. Patch by Torsten Landschoff.
| -rw-r--r-- | Lib/test/test_types.py | 2 | ||||
| -rw-r--r-- | Misc/NEWS | 4 | ||||
| -rw-r--r-- | Python/formatter_unicode.c | 7 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index ec10752e6a..11d95465a8 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -343,6 +343,8 @@ class TypesTests(unittest.TestCase): self.assertRaises(ValueError, 3 .__format__, ",n") # can't have ',' with 'c' self.assertRaises(ValueError, 3 .__format__, ",c") + # can't have '#' with 'c' + self.assertRaises(ValueError, 3 .__format__, "#c") # ensure that only int and float type specifiers work for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] + @@ -43,6 +43,10 @@ Core and Builtins replacement fields. It now matches the behavior of str.format() in this regard. Patches by Phil Elson and Ramchandra Apte. +- Issue #8931: Make alternate formatting ('#') for type 'c' raise an + exception. In versions prior to 3.5, '#' with 'c' had no effect. Now + specifying it is an error. Patch by Torsten Landschoff. + Library ------- diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index e3a8149841..056bb76902 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -846,6 +846,13 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format, " format specifier 'c'"); goto done; } + /* error to request alternate format */ + if (format->alternate) { + PyErr_SetString(PyExc_ValueError, + "Alternate form (#) not allowed with integer" + " format specifier 'c'"); + goto done; + } /* taken from unicodeobject.c formatchar() */ /* Integer input truncated to a character */ |
