Skip to content

gh-133986: Document string split algorithm when sep is None and maxsplit is 0 #133987

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

Merged
merged 2 commits into from
May 14, 2025

Conversation

tml
Copy link
Contributor

@tml tml commented May 14, 2025

If sep is not specified or is None and maxsplit is 0, only leading runs of consecutive whitespace are considered. This is contrary to (or, at least, underspecified in) the current documentation.

I have documented the observed behaviour, and added some example code.


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

@python-cla-bot
Copy link

python-cla-bot bot commented May 14, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Co-authored-by: Semyon Moroz <donbarbos@proton.me>
@nedbat nedbat merged commit 3e23047 into python:main May 14, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs May 14, 2025
@nedbat nedbat added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels May 14, 2025
@miss-islington-app
Copy link

Thanks @tml for the PR, and @nedbat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @tml for the PR, and @nedbat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 14, 2025
… maxsplit is 0 (pythonGH-133987)

* Document string split algorithm when sep is None and maxsplit is 0

* Update Doc/library/stdtypes.rst

Co-authored-by: Semyon Moroz <donbarbos@proton.me>

---------
(cherry picked from commit 3e23047)

Co-authored-by: Joey Smith <joeysmith@gmail.com>
Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 14, 2025
… maxsplit is 0 (pythonGH-133987)

* Document string split algorithm when sep is None and maxsplit is 0

* Update Doc/library/stdtypes.rst

Co-authored-by: Semyon Moroz <donbarbos@proton.me>

---------
(cherry picked from commit 3e23047)

Co-authored-by: Joey Smith <joeysmith@gmail.com>
Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
@bedevere-app
Copy link

bedevere-app bot commented May 14, 2025

GH-133992 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 14, 2025
@bedevere-app
Copy link

bedevere-app bot commented May 14, 2025

GH-133993 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 14, 2025
@The-Compiler
Copy link
Contributor

The-Compiler commented May 14, 2025

I'm a bit late I suppose, but I don't think this is specific to maxsplit=0?

>>> "   foo   bar   ".split(maxsplit=1)
['foo', 'bar   ']

terryjreedy pushed a commit that referenced this pull request May 15, 2025
…d maxsplit is 0 (GH-133987) (#133993)

---------
(cherry picked from commit 3e23047)

Co-authored-by: Joey Smith <joeysmith@gmail.com>
Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
terryjreedy pushed a commit that referenced this pull request May 15, 2025
…d maxsplit is 0 (GH-133987) (#133992)

gh-133986: Document string split algorithm when sep is None and maxsplit is 0 (GH-133987)
---------
(cherry picked from commit 3e23047)

Co-authored-by: Joey Smith <joeysmith@gmail.com>
Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
Co-authored-by: Semyon Moroz <donbarbos@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants