[Python-checkins] cpython (3.4): Closed issue #8931: Make alternate formatting for 'c' raise an exception. Patch

eric.smith python-checkins at python.org
Tue Apr 15 09:05:15 CEST 2014


http://hg.python.org/cpython/rev/16efa8d27e4c
changeset:   90317:16efa8d27e4c
branch:      3.4
parent:      90313:2031ff9f13a8
user:        Eric V. Smith <eric at trueblade.com>
date:        Tue Apr 15 03:05:02 2014 -0400
summary:
  Closed issue #8931: Make alternate formatting for 'c' raise an exception. Patch by Torsten Landschoff.

files:
  Lib/test/test_types.py     |  2 ++
  Misc/NEWS                  |  4 ++++
  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
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -343,6 +343,8 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,10 @@
   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. It had no effect, now trying to specify it is an error.
+  Patch by Torsten Landschoff.
+
 Library
 -------
 
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -846,6 +846,13 @@
                             " 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 */

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list