GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PEP 737: gh-111696: Add %T format to PyUnicode_FromFormat() by vstinner · Pull Request #111703 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Nov 3, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: PEP 737: PyUnicode_FromFormat(): Add %T format to format the type name of an object #111696

📚 Documentation preview 📚: https://cpython-previews--111703.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
vstinner requested a review from markshannon as a code owner November 3, 2023 17:08
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 3, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Nov 3, 2023
PEP 737: PyUnicode_FromFormat(): Add %T format to format the type name of an object #111696
Closed
@vstinner
vstinner force-pushed the fromformat_typename branch 3 times, most recently from 0ebff22 to 50923bf Compare November 4, 2023 00:36
@vstinner

vstinner commented Nov 4, 2023

Copy link
Copy Markdown
Member Author

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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner force-pushed the fromformat_typename branch from 50923bf to 6c09d87 Compare November 9, 2023 22:37
@vstinner
pythongh-111696: Add %T format to PyUnicode_FromFormat()
86da2a3
@vstinner
vstinner force-pushed the fromformat_typename branch from 6c09d87 to 86da2a3 Compare November 9, 2023 22:39
@vstinner

vstinner commented Nov 9, 2023

Copy link
Copy Markdown
Member Author

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 13, 2023

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@serhiy-storchaka

serhiy-storchaka commented Nov 14, 2023

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 29, 2023

Copy link
Copy Markdown
Member Author

My previous attempt in 2018: #9122

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 29, 2023

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Nov 29, 2023

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

vstinner commented Dec 20, 2023

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

Reviewers

@markshannon markshannon Awaiting requested review from markshannon

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@vstinner @serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.