summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric V. Smith <eric@trueblade.com>2014-04-16 02:37:55 (GMT)
committerEric V. Smith <eric@trueblade.com>2014-04-16 02:37:55 (GMT)
commita12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98 (patch)
tree3d395e27f831e78b5e9831ea1e855d4e125c303d
parent15b04eb42902f84fa3e35387b0c7c3391a204f65 (diff)
downloadcpython-a12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98.zip
cpython-a12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98.tar.gz
cpython-a12572ff3a62878f70cfb8fd4cf8c6bc4ac1ba98.tar.bz2
Close issue #8931: Make alternate formatting for 'c' raise an exception. Patch by Torsten Landschoff.
-rw-r--r--Lib/test/test_types.py2
-rw-r--r--Misc/NEWS4
-rw-r--r--Python/formatter_unicode.c7
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index ec10752..11d9546 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)] +
diff --git a/Misc/NEWS b/Misc/NEWS
index 4da2333..6d4a6e4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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 e3a8149..056bb76 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 */