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
Improve and consolidate f-strings docs #85583
Comments
[Creating a new issue from bpo-41045] I was just just trying to link to someone the documentation for f-strings, but:
I think we should:
|
I think this is an excellent idea. The main f-string docs being in a section titled "Lexical Analysis" never seemed very user-friendly. |
It's basically an accident that the only f-strings docs are in the language reference. Yes, they should be there, and the text there is pretty good for the reference, but there isn't much about them elsewhere outside of the tutorial, so everything links there. Maybe we need a section on them in the library part, of intermediate complexity between what's in the tutorial an what's in the reference. This could be on equal footing with the descriptions of % formatting and .format(), which seem to be quite extensive. We might also be able to share some text between .format() and f-strings, since the |
Hi Ezio, Would you see this being resolved in part by a HOWTO document? |
HOWTOs are generally used to explain how to accomplish a certain task, so I'm not sure if they are a good fit for this situation. In the list of proposed solutions in my first message, 1-3 should be quite easy to implement. This leaves us with 4-5. To summarize what we already have (let me know if I missed anything):
The lexical analysis is probably fine as is. The introduction in the tutorial should mention f-strings, include a couple of examples, and link to the documentation for more. The stdtypes page is already quite long and crowded, so I'm wary about adding more stuff in there. So, unless we add a separate page somewhere, the string page seems the best candidate, even if technically it should be about the string module. On top of items 1-3 of my previous message, to solve 4-5 I suggest to:
The string.rst page could then look something like: This should consolidate all the docs in two places: string.rst and lexical_analysis.rst (they have a different target, so the separation is ok). All other places can then refer to this. Once this is done, we can still decide to move these out of string.rst. |
Note that there already is something in the tutorial about f-strings (in |
Hi, Thanks Ezio for the detailed response.
To the best of my seeing there are only two places in the documentation that have information about f-strings. The tutorial[0] and the reference[1]
This is there[0] but it _IS_ hard to find, when you don't know it is there.
True. But is this wrong? In my feeling this is reference documentation. It should be accurate, complete and clear. It may not need to be "textbook-like". Some thoughts:
This is why I was thinking of a HOWTO. Going back to your original pain in msg371912, someone wanted the f-string documentation and: But now (and this is mainly to me) it appears that another problem is a need to consistently, clearly, and in one place describe the various elements/nuances/eccentricities of presenting data in Python:
I propose one of the following two:
!) above is similar to what you propose ... but different-ish. [0] https://docs.python.org/dev/tutorial/inputoutput.html#formatted-string-literals |
Thanks both for pointing out the additional section in inputoutput.rst that I initially missed.
The online docs seem updated, so I'm not sure why it's not working. Maybe you could try moving things around and see if you can make it work? You should be able to build the docs locally and test from there. You can also see if Sphinx raises any warning during the build process, try to move the
I noticed (or rather, I didn't :)!
I think this section is fine, the only thing that needs to be update is the link at the end of the section to point to the main f-string section that we will add elsewhere.
You might be right.
Both in the documentation and in the code, there are advantages in having everything on a single page/file (such as easier ctrl+f search) but also disadvantages. Given the goal of the page, I think keeping it monolithic is fine: it provides a summary of all the built-in types in a single place. Breaking it down into multiple pages will have other issues. If you make a page per type, you will have some pages that are very short, and it will be more difficult to get an overview of all the types, comparing them, and searching through all of them at once.
If I recall correctly that section has also been there, but initially it was just describing the standard way of doing string formatting, and when str.format() was added, it got renamed and the note at the top was added to link to the str.format() documentation. I guess that the str.format documentation ended up in string.rst because it was related to string.formatter, and the author wanted to keep them together.
Agreed, stdtypes.rst would be the right place where to document this, my only concerns were: 1) the size of the page (that as said above, is not such a big deal); 2) keeping str.format() and string.Formatter() together (but this is also not a huge concern). Also note that str.format() is not documented in stdtypes.rst, however there is an entry for str.format() with a clear link to the formatting docs, so I never had a problem finding it, even if I needed an extra click. [...]
What about doing the following:
Doing this would leave a gap in the built-in types page, and you would still want things things like string.Formatter and string.Template to be documented in string.rst. It also raises the question: where should we put this page?
One of the reasons why I'm not fond of the HOWTO idea, is that these are built-in features that need to be documented in the main documentation, where the string type is documented. It is my understanding that the HOWTOs are mostly meant as standalone (and somewhat external) additions that cover a specific topic in detail. While having an HOWTO on all the quirks and options for doing string formatting in Python does make sense, we would still have to cover it in the main docs, thus ending up duplicating a lot. For example the argparse tutorial (one of the HOWTOs), shows actual examples of how to use argparse, but the module itself and its API are already extensively documented in the argparse module documentation. The only way I could see it working is if we turned the "Format Examples" section in an HOWTO and add more examples specific to f-string, however when I wrote that section I think I tried to cover all the features and the end result was compact enough to fit in a single section. I'm also not sure there's much value in adding more examples and documentation about the old string formatting, string.Formatter, and string.Template, since nowadays they are rarely used (especially the last two). There are also another couple of thoughts I had, that however I haven't fully developed yet (so it's better to deal with them later or in another issue):
|
Hi,
So it seems that the .. index::[0] directive creates an index[1]. Both f-index and findex are available in it.
introduction.rst has a reference to "Formatted string literals" in the "See also:" box[5]. But I can still put an example here. Should we put both str.format() and f-strings, or make this exclusively for f-strings?
Ok. Please can we progress as follows: (Each as sequential and independent PR)
PS C:\> py -3.9
Python 3.9.0b5 (tags/v3.9.0b5:8ad7d50, Jul 20 2020, 18:35:09) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help(fstring)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'fstring' is not defined
>>> help(f-string)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'f' is not defined
>>>
[0] https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#index-generating-markup |
@ezio.melotti: What is this waiting for at this point? There was some good energy here but progress seems halted, waiting for some kind of decision. |
It seems ezio-melotti hesitates to continue the modifications in the PR #21552 (review) IMO, the PR improves enough the documentation, so it would be nice to merge it, even without the other changes. I'd like to help but I don't know how I could do that. @ezio.melotti, @amaajemyfren Are you still interested by this issue? How can I help you? |
Eric, do you want to approve and apply these PRs ? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: