Skip to content

gh-132661: PEP 750 documentation: second pass #137020

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Jul 22, 2025

* 97: ``!a`` ascii conversion
* 97: ``!a`` :func:`ASCII <ascii>` conversion (``ord('a')``)
* 114: ``!r`` :func:`repr` conversion (``ord('r')``)
* 115: ``!s`` :func:`string <str>` conversion (``ord('s')``)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just say that value, conversion and format_spec have the same meaning as in FormattedValue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantically I'd prefer to keep them apart, I could see a future extension to t-strings that relaxes the conversion flag restriction for example. If consensus is to de-duplicate, though, no strong objections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that even then, it might be good to point out only the ones that are actually different.

Comment on lines +78 to +79
template.strings: ('Hello, ', '!')
template.values: ( 'World', )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JessicaTegner: hello! This is Petr, we met at EuroPython.

Here is a “diagram” that aims to explain how t-string Template's strings and values are related, but I'm afraid it's only usable for sighted people. Any suggestions for improving this would be welcome.
The diagram is already included in Python 3.14 docs; you can read the rendered version here: https://docs.python.org/3.14/library/string.templatelib.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this problem when describing iter(Template) too -- how best to describe the "proper ordering" of template parts. We could do a worked example with displaying the list/tuple output perhaps?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @encukou it was nice meeting you.

After taking a look at the documentation, it's a bit angular where the diagram is supposed to be. I'm unsure if that's because I don't know what to look out for, it actually isn't on that page, or the screen reader skips it completely. Could you be more specific on where on the page it should be, so I can confirm what's going on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now.
Looks good to me, all though, if you aren't careful, you could miss the "!" item.
Maybe it would be better with a table representation, but idk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking!

If it looks good, let's keep it. A table might be too busy, and look too out of place among the other code blocks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense.
I'm personally fine with this example, but if we maybe wanted to make it easier for people new to python using a screen reader, the example could be reworded to use something other than the "!" symbol, which would make it more obvious to screen reader, that there's 2 strings in the "template.strings".
Kind of a NIT here - just throwing ideas out there - but I'm personally okay with this.

Comment on lines +564 to +566
A string literal with ``'f'`` or ``'F'`` in its prefix is a
:dfn:`formatted string literal`; see :ref:`f-strings`. The ``'f'`` may be
combined with ``'r'``, but not with ``'b'`` or ``'u'``, therefore raw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the original; the prefix is not in quotes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent here was to convey it's the literal character, hence the quotation marks. Especially on smaller screens (or reader mode, etc) the distinction between roman and typewriter text can be harder to see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Should we keep the quotes outside the literal text then -- use '``r``'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: this conflicts with my work-in-progress PR; let's do it there?

>>> name = "World"
>>> template = t"Hello {name}!"
>>> name = 'World'
>>> template = t'Hello, {name}!'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer leaving the comma out. It's better grammar, but makes the strings tuple harder to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was also partially in reference to that the proper phrase is "Hello, World[!]". The example is a little repetitive, I'll perhaps reintroduce the cheese-based ones from the PEP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just Wikipedia choosing the most correct-looking variation for the article :)

@davepeck
Copy link
Contributor

davepeck commented Jul 24, 2025

Overall these changes look great to me. Thanks @AA-Turner !

About my only detail comment is that I tried to avoid using commas in examples so the reprs were easier to read. Hence "Hello World" without the comma. I'd be happy to see cheese-based examples make a comeback. :-)

(Sorry for the slow review. I'm out of town on vacation right now -- back in another week.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting core review docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy