]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Closed issue #8931: Make alternate formatting for 'c' raise an exception. Patch by...
authorEric V. Smith <eric@trueblade.com>
Tue, 15 Apr 2014 07:05:02 +0000 (03:05 -0400)
committerEric V. Smith <eric@trueblade.com>
Tue, 15 Apr 2014 07:05:02 +0000 (03:05 -0400)
Lib/test/test_types.py
Misc/NEWS
Python/formatter_unicode.c

index ec10752e6a2ae0eac233c1cdd9bf7cd8ed858b54..11d95465a81312a6b3afa47e1fbe803c8f6f6349 100644 (file)
@@ -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)] +
index 45401d6cd8a50ecac5b95b8e74f2c38fd9a7c96b..a158999f98292428e0c2f20db9d135ded60647b4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -34,6 +34,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. It had no effect, now trying to specify it is an error.
+  Patch by Torsten Landschoff.
+
 Library
 -------
 
index e3a814984151b6e85c9afec1c2a090bee0b22513..056bb76902597e8b959fa53dcd58386102b10c99 100644 (file)
@@ -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 */