Skip to content

Commit a46da7a

Browse files
committed
inherit maxchar of field value where needed (closes #14648)
1 parent 30267cc commit a46da7a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lib/test/test_unicode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ def __str__(self):
10561056
self.assertEqual('%f' % INF, 'inf')
10571057
self.assertEqual('%F' % INF, 'INF')
10581058

1059+
self.assertEqual(format("\u0410\u0411\u0412", "s"), "АБВ")
1060+
10591061
def test_startswith_endswith_errors(self):
10601062
for meth in ('foo'.startswith, 'foo'.endswith):
10611063
with self.assertRaises(TypeError) as cm:

Python/formatter_unicode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
747747
len = format->precision;
748748
}
749749

750+
if (len)
751+
maxchar = PyUnicode_MAX_CHAR_VALUE(value);
752+
750753
calc_padding(len, format->width, format->align, &lpad, &rpad, &total);
751754

752755
if (lpad != 0 || rpad != 0)

0 commit comments

Comments
 (0)