diff -r 19c5fb692b39 Lib/test/test_str.py --- a/Lib/test/test_str.py Tue May 12 19:15:53 2015 -0400 +++ b/Lib/test/test_str.py Wed May 13 11:59:24 2015 +0300 @@ -428,6 +428,13 @@ class StrTest( self.assertEqual('{:{f}}{g}{}'.format(1, 3, g='g', f=2), ' 1g3') self.assertEqual('{f:{}}{}{g}'.format(2, 4, f=1, g='g'), ' 14g') + def test_format_c_overflow(self): + # issue #7267 + with test_support.check_py3k_warnings(): + '{0:c}'.format(-1) + with test_support.check_py3k_warnings(): + '{0:c}'.format(256) + def test_buffer_is_readonly(self): self.assertRaises(TypeError, sys.stdin.readinto, b"") diff -r 19c5fb692b39 Misc/NEWS --- a/Misc/NEWS Tue May 12 19:15:53 2015 -0400 +++ b/Misc/NEWS Wed May 13 11:59:24 2015 +0300 @@ -10,6 +10,9 @@ What's New in Python 2.7.11? Core and Builtins ----------------- +- Issue #7267: format(int, 'c') now emits Py3k deprecation warning when the + argument is not in range(0, 256). + Library ------- diff -r 19c5fb692b39 Objects/stringlib/formatter.h --- a/Objects/stringlib/formatter.h Tue May 12 19:15:53 2015 -0400 +++ b/Objects/stringlib/formatter.h Wed May 13 11:59:24 2015 +0300 @@ -789,6 +789,7 @@ format_int_or_long_internal(PyObject *va x = PyLong_AsLong(value); if (x == -1 && PyErr_Occurred()) goto done; +#if STRINGLIB_IS_UNICODE #ifdef Py_UNICODE_WIDE if (x < 0 || x > 0x10ffff) { PyErr_SetString(PyExc_OverflowError, @@ -804,6 +805,12 @@ format_int_or_long_internal(PyObject *va goto done; } #endif +#else + if (x < 0 || x > 0xff) { + if (PyErr_WarnPy3k("%c arg not in range(0x100)", 1) < 0) + goto done; + } +#endif numeric_char = (STRINGLIB_CHAR)x; pnumeric_chars = &numeric_char; n_digits = 1;