-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
base: main
Are you sure you want to change the base?
Conversation
* 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')``) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
template.strings: ('Hello, ', '!') | ||
template.values: ( 'World', ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part, in the third code-block: https://docs.python.org/3.14/library/string.templatelib.html#string.templatelib.Template
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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``'
?
There was a problem hiding this comment.
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}!' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
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.) |
Follows on from #135229. cc @lysnikolaou @davepeck.
A
📚 Documentation preview 📚: https://cpython-previews--137020.org.readthedocs.build/