-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-73123: Add a keepempty argument to string, bytes and bytearray split methods #26222
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
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.
PyUncode_Split()
and PyUnicode_RSplit()
are in the stable ABI and API. You cannot modify the function arguments. Instead you have to create additional functions.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Thank you for letting me know about the API / ABI. I have changed this PR so that it leaves I have decided that the C API interfaces add little extra value and so have removed them. If it is decided later that these are useful then they can be re-added by reverting commit f95b254. Now that I have made the requested changes; please review again. |
Thanks for making the requested changes! @tiran: please review the changes made to this pull request. |
Could a maintainer approve running the last two jobs of the CI workflow for me please. |
I've left a comment in the issue tracker, I think there may be a potential problem with the API. |
This PR is stale because it has been open for 30 days with no activity. |
This PR adds an optional
keepempty
argument to string.split (and similarly for bytes.split, bytearray.split and UserString.split). As described in issue bpo-28937:keepempty
is true then empty strings are never stripped out of the result array.keepempty
is false then empty strings are always stripped out of the result array.keepempty
isNone
(the default) then the current behaviour is followed in which empty strings are stripped out of the result array if and only if the separator string isNone
.To do this it uses a new splitting algorithm which has been designed to be compatible with the existing
maxsplit
argument. This is roughly:A number of tests have been added to check the correct behaviour.
https://bugs.python.org/issue28937