bpo-34595: Add %T format to PyUnicode_FromFormatV() (GH-9080) · python/cpython@886483e · GitHub
Skip to content

Commit 886483e

Browse files
authored
bpo-34595: Add %T format to PyUnicode_FromFormatV() (GH-9080)
* Add %T format to PyUnicode_FromFormatV(), and so to PyUnicode_FromFormat() and PyErr_Format(), to format an object type name: equivalent to "%s" with Py_TYPE(obj)->tp_name. * Replace Py_TYPE(obj)->tp_name with %T format in unicodeobject.c. * Add unit test on %T format. * Rename unicode_fromformat_write_cstr() to unicode_fromformat_write_utf8(), to make the intent more explicit.
1 parent 254a466 commit 886483e

4 files changed

Lines changed: 66 additions & 53 deletions

File tree

Doc/c-api/unicode.rst

Lines changed: 6 additions & 0 deletions

Lib/test/test_unicode.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,10 @@ def check_format(expected, format, *args):
26552655
check_format(r"%A:'abc\xe9\uabcd\U0010ffff'",
26562656
b'%%A:%A', 'abc\xe9\uabcd\U0010ffff')
26572657

2658+
# test %T (object type name)
2659+
check_format(r"type name: str",
2660+
b'type name: %T', 'text')
2661+
26582662
# test %V
26592663
check_format('repr=abc',
26602664
b'repr=%V', 'abc', b'xyz')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:c:func:`PyUnicode_FromFormatV`: add ``%T`` format to
2+
:c:func:`PyUnicode_FromFormatV`, and so to :c:func:`PyUnicode_FromFormat`
3+
and :c:func:`PyErr_Format`, to format an object type name: equivalent to
4+
"%s" with ``Py_TYPE(obj)->tp_name``.

Objects/unicodeobject.c

Lines changed: 52 additions & 53 deletions

0 commit comments

Comments
 (0)