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 — gh-106318: Add examples for the `str` methods in collapsible sections by adorilson · Pull Request #111743 · python/cpython

Conversation

@adorilson

@adorilson adorilson commented Nov 4, 2023 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This PR complements #105670, turning the examples into collapsible sections, as suggested in #106318.

I would like a "go ahead" to continue the work.


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

  • Issue: Add examples to docs for str methods #106318

Sorry, something went wrong.

Uh oh!

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

All reactions
adorilson added 30 commits June 11, 2023 19:43
@adorilson
[Doc] Added snippet code to str.join method
5508700
@adorilson
[Doc] Added snippet code to str.ljust method
e388d45
@adorilson
[Doc] Added snippet code to str.rjust method
d8407ba
@adorilson
[Doc] Added 'See also' in str.lstrip and str.rstrip methods from one …
08b88ef
…to the another
@adorilson
[Doc] Added snippet code to str.maketrans method
52e3a6b
@adorilson
[Doc] Added snippet code to str.translate method
dee059c
@adorilson
[Doc] Added snippet code to str.partition method
1671497
@adorilson
[Doc] Added snippet code to str.replace method
c832623
@adorilson
[Doc] Added snippet code to str.rfind method
0be8170
@adorilson
[Doc] Added snippet code to str.rindex method
ff65bd2
@adorilson
[Doc] Added snippet code to str.rpartition method
322c88c
@adorilson
[DOC] minor change
3a473df
@adorilson
[Doc] Added snippet code to str.rsplit method
b653693
@adorilson
[Doc] Added snippet code to str.startswith method
1b412cb
@adorilson
[Doc] Added snippet code to str.swapcase method
fb56441
@adorilson
[Doc] Added snippet code to str.upper method
04a5212
@adorilson
[DOC] Added snipped code in str.capitalize
8771775
@adorilson
[DOC] Add snippet code in str.casefold and str.lower methods
f2e224c
@adorilson
[DOC] Added snippet code in str.center method
1d39f92
@adorilson
[DOC] Added snippet code in str.count method
b3a70b6
@adorilson
[DOC] fix typo
37477f8
@adorilson
[DOC] Added snippet code in str.encode method
f9a7293
@adorilson
[DOC] Added snippet code to str.endswith method
2e54cb0
@adorilson
[DOC] Added snippet code with \n to str.expandtabs method
96d9bf6
@adorilson
[DOC] Added snippet code to str.index method
d1dc7e0
@adorilson
[DOC] Added snippet code to str.isalnum method
8661d8e
@adorilson
[DOC] Added snippet code in str.isalpha method
9e1f289
@adorilson
[DOC] Added snippet code in str.isascii method
9e361d8
@adorilson
[DOC] Added snippet code to str.isdecimal method
09a463a
@adorilson
[Doc] Added snippet code to str.isdigit method
641de5c
@hauntsaninja

hauntsaninja commented Jan 23, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Shipping these examples somewhere else would be worse for users IMO. If I want to look up what str.maketrans does, I'm going to look at the str.maketrans docs, not read through the whole page

In these discussion about .. raw:: I'm having a hard time understanding whether objections are fundamental to the proposal or whether they're predicated on sphinx implementation issues. If we had a magic sphinx wand, are inline collapsible sections something you (or other docs-community folks) would be okay with or not?

AlexWaygood reacted with thumbs up emoji adorilson reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@ezio-melotti

ezio-melotti commented Jan 24, 2024

Copy link
Copy Markdown
Member

If I want to look up what str.maketrans does, I'm going to look at the str.maketrans docs, not read through the whole page

This is a discoverability problem, but it can be easily be solved by turning the "See examples" text that expands the collapsed section in a link to the bottom of the page, where the section with all the examples is.

In these discussion about .. raw:: I'm having a hard time understanding whether objections are fundamental to the proposal or whether they're predicated on sphinx implementation issues.

There are a few issues at different levels:

  • .. raw:: itself is not an elegant solution implementation-wise, since it requires hardcoding raw HTML and also leads to repetition and increases the risk of errors (I'm not sure Sphinx is able to check markup errors in raw directives).
  • using existing plugins solves these problems, but introduces a new issue: the doc should be buildable without third-part extensions.
  • both these solutions, afaik, have the additional problem that they only works with the HTML builder, and not with the other builders -- something that we also want to support (adopting graceful degradation is an acceptable compromise here).

If we had a magic sphinx wand, are inline collapsible sections something you (or other docs-community folks) would be okay with or not?

If all the problems listed above were magically solved (i.e. if Sphinx added a built-in support for collapsible sections that words with all builders), then they could definitely be a useful tool. They still have some minor issues (e.g. iirc ctrl+f doesn't detect text within a collapsed section and they might be easy to miss while skimming through a page), but at that point the pros might outweigh the cons.

Finally, there's also another higher-level and more general discussion that we should have (probably not here, the next doc meeting might be better): should we have some convention on where to put examples?

We don't want to end up in a situation where a page uses collapsible sections, another has examples at the top, another at the bottom, another in the middle, another in a separate page, etc. If we agree on some conventions, it will also be easier for users to set their expectations and know where to look.

All reactions

Sorry, something went wrong.

Uh oh!

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

@adorilson
Doc: Make str methods example collapsible - pt 4
47ba07f
adorilson
adorilson commented Jan 27, 2024
View reviewed changes
Comment thread Doc/library/stdtypes.rst
</dd>


.. _meth-str-join:

@adorilson adorilson Jan 27, 2024

Copy link
Copy Markdown
Contributor Author

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.

Is this a useful directive? If yes, can I add to other methods in this PR or another?

Sorry, something went wrong.

Uh oh!

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

All reactions
adorilson added 4 commits January 29, 2024 20:54
@adorilson
Doc: Make str methods example collapsible - pt 5
8e982bf
@adorilson
Merge branch 'main' into str_methods_collapsible
9abd8fe
@adorilson
Doc: Make str methods example collapsible - pt 6
bd831e2
@adorilson
Doc: Make str methods example collapsible - pt 7
b1169f4
@ezio-melotti

ezio-melotti commented Feb 11, 2024

Copy link
Copy Markdown
Member

Finally, there's also another higher-level and more general discussion that we should have (probably not here, the next doc meeting might be better): should we have some convention on where to put examples?

We discussed this during the last meeting, and we agreed that a better approach would be to have a couple of simpler/short examples inline (i.e. just after the fuction doc) and possibly link to an "Example" section with more examples at the bottom. If we follow this approach, we don't need to worry about having collapsible sections and the issues that come along with those.

All reactions

Sorry, something went wrong.

Uh oh!

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

@hauntsaninja

hauntsaninja commented Feb 11, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Great! The examples in this PR are all simple and short.

So it sounds like we should just keep these in line, without the collapsible sections. And as per your last comment, if Sphinx develops better collapsible section tech in the future, we can incorporate this (and I'm happy to do the work for this myself).

In case folks read this thread later want a concrete example of what that would look like, here's the equivalent Go docs with collapsible sections: https://pkg.go.dev/strings#pkg-functions (to keep in theme with the Rob Pike quote from above )

ezio-melotti reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@adorilson

adorilson commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

So it sounds like we should just keep these in line, without the collapsible sections. And as per your last comment, if Sphinx develops better collapsible section tech in the future, we can incorporate this (and I'm happy to do the work for this myself).

Do you mean reject this PR in favor of #105670 ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@ezio-melotti

ezio-melotti commented Feb 12, 2024

Copy link
Copy Markdown
Member

Do you mean reject this PR in favor of #105670 ?

Are those the same examples, just without collapsible sections?

All reactions

Sorry, something went wrong.

Uh oh!

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

@adorilson

adorilson commented Feb 12, 2024

Copy link
Copy Markdown
Contributor Author

Do you mean reject this PR in favor of #105670 ?

Are those the same examples, just without collapsible sections?

Exactly. For this PR, I only forked that branch and added the collapsible sections.

ezio-melotti and blaisep reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@hugovk hugovk removed the needs backport to 3.11 only security fixes label Apr 11, 2024
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.13 only security fixes label May 9, 2024
@blaisep

blaisep commented May 22, 2024

Copy link
Copy Markdown
Contributor

OK, I have been reviewing "simple" PR docs and it seems like the consensus is to use #105670 and then close this one ( #111743 )

@adorilson , if you agree, please close this PR.

adorilson reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@hauntsaninja

hauntsaninja commented May 22, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Silly question, where is the consensus?

All reactions

Sorry, something went wrong.

Uh oh!

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

@blaisep

blaisep commented May 22, 2024

Copy link
Copy Markdown
Contributor

Silly question, where is the consensus?

Well, it seems that @adorilson , @ezio-melotti , @hugovk , @terryjreedy , @CAM-Gerlach , @encukou all agree that the examples are useful and that we should use them without the additional formatting.
@hauntsaninja , do you have an objection to adding the examples?

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@blaisep blaisep mentioned this pull request May 22, 2024
gh-106318: Add string method examples #119445
Closed
@hauntsaninja

hauntsaninja commented May 23, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

I'm strongly in favour of adding the examples, see e.g. #111743 (review) and my other reviews on this and related PRs

But last I checked, Ezio and others weren't sure what the best way and place and format to add them was. I still can't find discussion that comes to a consensus on this (i.e. to go with #105670) and was curious, which is why I asked :-)

(Personally, I'm fine with any option that adds the examples, with a very mild preference for collapsible sections)

AlexWaygood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@adorilson

adorilson commented May 23, 2024

Copy link
Copy Markdown
Contributor Author

But last I checked, Ezio and others weren't sure what the best way and place and format to add them was. I still can't find discussion that comes to a consensus on this (i.e. to go with #105670) and was curious, which is why I asked :-)

In fact, maybe "consensus" is a strong word.
But I understood that adding examples without collapsible sections was a decision, and @ezio-melotti would review #105670 .

All reactions

Sorry, something went wrong.

Uh oh!

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

@blaisep

blaisep commented May 24, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

I see. Well, I think the examples are very good, so I made a bit of a compromise by trying to integrate them more closely with the prose they describe, Doc/library/stdtypes.rst
My motivation is to expedite getting these examples into the docs.
If PR #119445 is not useful, I'll close it.

adorilson reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@adorilson

adorilson commented May 24, 2024

Copy link
Copy Markdown
Contributor Author

Hi, @blaisep.

I've seen your changes on my PR. And I like it.

I'll keep this PR open until some other related PR is merged. But if some core developers want to close it, go ahead. I think this (and also #105670 ) can be closed in favour of #119445.

blaisep reacted with thumbs up emoji blaisep reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@picnixz

picnixz commented May 28, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

By the way, we are currently in the process of reviving sphinx-doc/sphinx#10532 which could make this PR much cleaner in the future. I cannot give you a merge ETA because Adam and Chris seem quite busy but I personally hope that we can make it for the next Sphinx release (or the one after).

EDIT: I know that this PR was already mentioned but since it was in January and we had some activity in April, I wanted to mention that we did not forget the use-case.

adorilson reacted with thumbs up emoji hauntsaninja reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@hugovk hugovk removed the needs backport to 3.12 only security fixes label Apr 10, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@StanFromIreland

StanFromIreland commented Jan 11, 2026

Copy link
Copy Markdown
Member

This work is ongoing via many small PRs without the collapsible sections, as such, I will close this PR.

hugovk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@StanFromIreland StanFromIreland closed this Jan 11, 2026
@StanFromIreland StanFromIreland removed needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja left review comments
@ezio-melotti ezio-melotti ezio-melotti left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Todo

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.

9 participants

@adorilson @AA-Turner @hugovk @hauntsaninja @ezio-melotti @blaisep @picnixz @StanFromIreland @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.