Skip to content
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

Allow "maxsplit" argument to str.split() to be passed as a keyword argument #58289

Closed
ncoghlan opened this issue Feb 22, 2012 · 7 comments
Closed
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

BPO 14081
Nosy @ncoghlan, @ezio-melotti, @merwok
Files
  • issue14081.diff: Patch + tests
  • issue14081-2.diff
  • 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:

    assignee = 'https://github.com/ezio-melotti'
    closed_at = <Date 2012-02-26.07:44:14.924>
    created_at = <Date 2012-02-22.01:54:09.836>
    labels = ['interpreter-core', 'type-feature']
    title = 'Allow "maxsplit" argument to str.split() to be passed as a keyword argument'
    updated_at = <Date 2012-02-26.07:44:14.922>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2012-02-26.07:44:14.922>
    actor = 'ezio.melotti'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2012-02-26.07:44:14.924>
    closer = 'ezio.melotti'
    components = ['Interpreter Core']
    creation = <Date 2012-02-22.01:54:09.836>
    creator = 'ncoghlan'
    dependencies = []
    files = ['24597', '24625']
    hgrepos = []
    issue_num = 14081
    keywords = ['patch']
    message_count = 7.0
    messages = ['153920', '153924', '154130', '154194', '154222', '154311', '154312']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'ezio.melotti', 'eric.araujo', 'tshepang', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14081'
    versions = ['Python 3.3']

    @ncoghlan
    Copy link
    Contributor Author

    Currently, setting maxsplit for the default "any whitespace" behaviour requires the following cryptic incantation:

    'do re mi fa'.split(None, 1)
    

    That would be significantly more comprehensible as:

    'do re mi fa'.split(maxsplit=1)
    

    (I noticed this when trying to figure out why http://hyperpolyglot.org/scripting#split-notes resorted to using the re module to achieve this)

    @ncoghlan ncoghlan added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Feb 22, 2012
    @ezio-melotti
    Copy link
    Member

    +1
    Patch attached.

    @ezio-melotti ezio-melotti self-assigned this Feb 22, 2012
    @ezio-melotti
    Copy link
    Member

    New patch that changes .rsplit() too and updates docs and docstrings.

    @merwok
    Copy link
    Member

    merwok commented Feb 25, 2012

    LGTM.

    (Nick: I think the author directly translated the regex function calls from other languages to using re in Python.)

    @ncoghlan
    Copy link
    Contributor Author

    Ezio: I spotted an extraneous '[' hanging around in the updated doc signature for split, but otherwise looked fine.

    Éric: you're probably right, but I was sending them a note to suggest a simpler alternative, only to discover that the obvious approach of "maxsplit=1" didn't actually work.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 26, 2012

    New changeset db968ac2b82c by Ezio Melotti in branch 'default':
    bpo-14081: The sep and maxsplit parameter to str.split, bytes.split, and bytearray.split may now be passed as keyword arguments.
    http://hg.python.org/cpython/rev/db968ac2b82c

    @ezio-melotti
    Copy link
    Member

    Fixed!
    Thanks for the reviews and for spotting the extra '['.
    (While suggesting the use of maxsplit, be aware that str.split uses -1 as default value, whereas re.split uses 0.)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants