Skip to content

PEP 737: gh-111696: Add %T format to PyUnicode_FromFormat() #111703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Nov 3, 2023

@vstinner
Copy link
Member Author

vstinner commented Nov 4, 2023

I updated my PR:

  • Remove the change: Add T and "#T" formats to type.__format__().
  • Exchange %T and %#T format: %T is now the short type name, and %#T is the long type name.

@vstinner vstinner force-pushed the fromformat_typename branch from 50923bf to 6c09d87 Compare November 9, 2023 22:37
@vstinner vstinner force-pushed the fromformat_typename branch from 6c09d87 to 86da2a3 Compare November 9, 2023 22:39
@vstinner
Copy link
Member Author

vstinner commented Nov 9, 2023

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 %#T format to PyUnicode_FromFormat() if needed.
  • Add a type.__fullyqualname__ attribute.
  • Add T and #T formats to type.__format__().

Extended the API later is not incompatible with this change: they would be additions.

@vstinner
Copy link
Member Author

@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.

@serhiy-storchaka
Copy link
Member

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.

@vstinner
Copy link
Member Author

My previous attempt in 2018: #9122

@vstinner
Copy link
Member Author

Previous attempt, merged commit 886483e, which was reverted a few days later.

@vstinner
Copy link
Member Author

I wrote PEP 737 – Unify type name formatting for these changes: see the PEP discussion.

@vstinner vstinner changed the title gh-111696: Add %T format to PyUnicode_FromFormat() PEP 737: gh-111696: Add %T format to PyUnicode_FromFormat() Dec 1, 2023
@vstinner
Copy link
Member Author

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.

@vstinner vstinner closed this Dec 20, 2023
@vstinner vstinner deleted the fromformat_typename branch December 20, 2023 10:56
@vstinner vstinner restored the fromformat_typename branch March 14, 2024 14:03
@vstinner vstinner deleted the fromformat_typename branch January 14, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants