Skip to content

gh-154610: Add !R to f-string and %#R to PyUnicode_FromFormat() - #157685

Closed
vstinner wants to merge 6 commits into
python:mainfrom
vstinner:format_alt_repr
Closed

vstinner wants to merge 6 commits into
python:mainfrom
vstinner:format_alt_repr

Conversation

@vstinner

@vstinner vstinner commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Similar to %R, but don't call __repr__() on str subclasses.

Similar to %R, but don't call __str__() on str subclasses.
@vstinner

Copy link
Copy Markdown
Member Author

If this change is accepted and merged, I will update my PR gh-154614 to use %#R instead of %R.

@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34618427 | 📁 Comparing 6507b80 against main (8759666)

  🔍 Preview build  

3 files changed
± c-api/unicode.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@vstinner
vstinner marked this pull request as draft September 17, 2026 15:50
@vstinner vstinner changed the title gh-154610: Add %#R format to PyUnicode_FromFormat() gh-154610: Add !R to f-string and %#R to PyUnicode_FromFormat() Sep 17, 2026
@vstinner

Copy link
Copy Markdown
Member Author

@vstinner

Copy link
Copy Markdown
Member Author

ruff check fails in the Lint CI:

Error: Lib/test/test_fstring.py:1374:33: invalid-syntax: f-string: invalid conversion character
Error: Lib/test/test_tstring.py:114:26: invalid-syntax: t-string: invalid conversion character

I failed to find a way to ignore invalid syntax per line in ruff.

@vstinner

Copy link
Copy Markdown
Member Author

Adding new conversion formats didn't convince anymore: see https://discuss.python.org/t/add-r-conversion-to-f-string-and-str-format-to-format-error-messages/109098/12. So I prefer to abandon my idea and move back to my initial plan to replacing str() with repr() in AttributeError error message: see my PR #154614.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Tests in the Lib/test dir topic-C-API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant