diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-04-08 16:27:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 16:27:25 (GMT) |
commit | 24a2bd048115efae799b0a9c5dd9fbb7a0806978 (patch) | |
tree | 38bf066ab930bebc5bbe661478d0ded22e5bafb5 /Lib/test | |
parent | 1a6594f66166206b08f24c3ba633c85f86f99a56 (diff) | |
download | cpython-24a2bd048115efae799b0a9c5dd9fbb7a0806978.zip cpython-24a2bd048115efae799b0a9c5dd9fbb7a0806978.tar.gz cpython-24a2bd048115efae799b0a9c5dd9fbb7a0806978.tar.bz2 |
gh-117642: Fix PEP 737 implementation (GH-117643)
* Fix implementation of %#T and %#N (they were implemented as %T# and
%N#).
* Restore tests removed in gh-116417.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_capi/test_unicode.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_capi/test_unicode.py b/Lib/test/test_capi/test_unicode.py index a64c75c..a69f817 100644 --- a/Lib/test/test_capi/test_unicode.py +++ b/Lib/test/test_capi/test_unicode.py @@ -650,6 +650,40 @@ class CAPITest(unittest.TestCase): check_format('\U0001f4bb+' if sizeof(c_wchar) > 2 else '\U0001f4bb', b'%.2lV', None, c_wchar_p('\U0001f4bb+\U0001f40d')) + # test %T + check_format('type: str', + b'type: %T', py_object("abc")) + check_format(f'type: st', + b'type: %.2T', py_object("abc")) + check_format(f'type: str', + b'type: %10T', py_object("abc")) + + class LocalType: + pass + obj = LocalType() + fullname = f'{__name__}.{LocalType.__qualname__}' + check_format(f'type: {fullname}', + b'type: %T', py_object(obj)) + fullname_alt = f'{__name__}:{LocalType.__qualname__}' + check_format(f'type: {fullname_alt}', + b'type: %#T', py_object(obj)) + + # test %N + check_format('type: str', + b'type: %N', py_object(str)) + check_format(f'type: st', + b'type: %.2N', py_object(str)) + check_format(f'type: str', + b'type: %10N', py_object(str)) + + check_format(f'type: {fullname}', + b'type: %N', py_object(type(obj))) + check_format(f'type: {fullname_alt}', + b'type: %#N', py_object(type(obj))) + with self.assertRaisesRegex(TypeError, "%N argument must be a type"): + check_format('type: str', + b'type: %N', py_object("abc")) + # test variable width and precision check_format(' abc', b'%*s', c_int(5), b'abc') check_format('ab', b'%.*s', c_int(2), b'abc') |