summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-23 10:55:29 -0400
committerBenjamin Peterson <benjamin@python.org>2012-04-23 10:55:29 -0400
commit80d07f825108761af9fe2ac79c1ef50289c07c08 (patch)
treeb9c87aef9fe754677fd5eb6220419647343e7400
parent1cf5aa910649bd831cad8f87963277025deb0695 (diff)
downloadcpython-git-80d07f825108761af9fe2ac79c1ef50289c07c08.tar.gz
inherit maxchar of field value where needed (closes #14648)
-rw-r--r--Lib/test/test_unicode.py2
-rw-r--r--Python/formatter_unicode.c3
2 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 813d59fd3c..7b0397ef7e 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1056,6 +1056,8 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual('%f' % INF, 'inf')
self.assertEqual('%F' % INF, 'INF')
+ self.assertEqual(format("\u0410\u0411\u0412", "s"), "АБВ")
+
def test_startswith_endswith_errors(self):
for meth in ('foo'.startswith, 'foo'.endswith):
with self.assertRaises(TypeError) as cm:
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
index 58e66e0d90..5e5b19f7fe 100644
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -747,6 +747,9 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
len = format->precision;
}
+ if (len)
+ maxchar = PyUnicode_MAX_CHAR_VALUE(value);
+
calc_padding(len, format->width, format->align, &lpad, &rpad, &total);
if (lpad != 0 || rpad != 0)