PEP 737: gh-111696: Add %T format to PyUnicode_FromFormat() by vstinner · Pull Request #111703 · python/cpython
I updated my PR:
- Remove the change: Add
Tand "#T" formats totype.__format__(). - Exchange
%Tand%#Tformat:%Tis now the short type name, and%#Tis the long type name.
I reduced this PR to the bare minimum, non controversial and most important: only add %T format just to add a type name (type.__name__).
Later, we can extend the API:
- Add a
%#Tformat toPyUnicode_FromFormat()if needed. - Add a
type.__fullyqualname__attribute. - Add
Tand#Tformats totype.__format__().
Extended the API later is not incompatible with this change: they would be additions.
@serhiy-storchaka: Are you ok with this minor addition to PyUnicode_FromFormat()?
My work on the limited C API is blocked by this missing feature. As I wrote previously, the format can be extended later if someone wants to cover most cases, add an alternative format, etc.
I would prefer to make the size modifier mandatory and use it as the format specifier in type.__format__. So you can write
PyUnicode_FromFormat("%zT", Py_TYPE(obj)) in C and f"{type(obj):z}" in Python.
It is also less ambiguous.
My previous attempt in 2018: #9122
Previous attempt, merged commit 886483e, which was reverted a few days later.
vstinner
changed the title
gh-111696: Add %T format to PyUnicode_FromFormat()
PEP 737: gh-111696: Add %T format to PyUnicode_FromFormat()
PEP 737 changed the API since this PR was created. I close this PR for now and will create a new one (or maybe reopen this PR) since PEP 737 will be approved.