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

Make namedtuple "verbose" and "rename" parameters into keyword only arguments #69814

Closed
rhettinger opened this issue Nov 15, 2015 · 13 comments
Closed
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

rhettinger commented Nov 15, 2015

BPO 25628
Nosy @gvanrossum, @rhettinger, @serhiy-storchaka
Files
  • namedtuple_keywords.diff
  • namedtuple_keywords_deprecate.patch
  • 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/rhettinger'
    closed_at = <Date 2016-08-16.18:02:23.070>
    created_at = <Date 2015-11-15.19:21:13.347>
    labels = ['type-feature', 'library']
    title = 'Make namedtuple "verbose" and "rename" parameters into keyword only arguments'
    updated_at = <Date 2016-08-16.18:02:23.069>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2016-08-16.18:02:23.069>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2016-08-16.18:02:23.070>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2015-11-15.19:21:13.347>
    creator = 'rhettinger'
    dependencies = []
    files = ['41049', '41051']
    hgrepos = []
    issue_num = 25628
    keywords = ['patch']
    message_count = 13.0
    messages = ['254689', '254693', '254712', '254716', '254718', '254719', '264942', '264984', '264986', '264989', '267783', '272765', '272870']
    nosy_count = 4.0
    nosy_names = ['gvanrossum', 'rhettinger', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue25628'
    versions = ['Python 3.6']

    @rhettinger
    Copy link
    Contributor Author

    rhettinger commented Nov 15, 2015

    This is a usability and readability improvement made possible by Python 3's keyword only arguments.

    Usability is improved by getting a much less confusing response from the following mistake:

        namedtuple('Point', 'x', 'y')
                                  ^--- invisibly goes to the "verbose" argument 

    The "verbose" argument is normally used interactively (much like help() and dis()) or is used with a keyword argument, so it is unlikely that existing scripts will be much affected. For the rare cases, the remediation is simple and improves code clarity (replacing "True" with "verbose=True").

    @rhettinger rhettinger added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 15, 2015
    @rhettinger rhettinger changed the title Make namedtuple "verbose" and "renanme" parameters into keyword only arguments Make namedtuple "verbose" and "rename" parameters into keyword only arguments Nov 15, 2015
    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Nov 15, 2015

    I like the idea. But this is backward incompatible change. I would first add a warning.

    Here is a patch. Yes, the code looks a little cumbersome, but this is only for one or two releases.

    @rhettinger
    Copy link
    Contributor Author

    rhettinger commented Nov 16, 2015

    I don't think a warning is necessary because of what "verbose" does.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Nov 16, 2015

    Existing scripts can contain passing positional 'rename' argument: namedtuple('Point', 'x y', False, True).

    @rhettinger
    Copy link
    Contributor Author

    rhettinger commented Nov 16, 2015

    My judgment call is that the keyword-only change can be made directly, that the costs and clutter of deprecation and delay aren't worth in it this case, that the nature of the "verbose" and "rename" arguments puts this in the rare-to-non-existent category, that any remediation would be trivial (easier than shutting-off a warning), and that the user's come out ahead with the cleaner cut-over in this case. There's no value in being pedantic on this one, some judgment is required.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Nov 16, 2015

    OK, leave it to you. But may be worth to add a versionchanged directive.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented May 6, 2016

    Ping.

    If the keyword-only changes can be made without deprecation, I would want to make such changes for json functions (bpo-18726). json.dump() takes 11 positional parameters!

    Guido, what you say about this?

    @gvanrossum
    Copy link
    Member

    gvanrossum commented May 6, 2016

    I think such a change can be safely made in a feature release (say 3.6) without further deprecation. But not in a bugfix release (say 3.5.2).

    @gvanrossum
    Copy link
    Member

    gvanrossum commented May 6, 2016

    And by "safely" I mean that I don't mind if some code breaks when they upgrade to a new feature release.

    FWIW the code most likely to break is code that wraps these functions with an identical interface.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented May 6, 2016

    Then namedtuple_keywords.diff LGTM. But please document changes.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Jun 8, 2016

    Ping.

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented Aug 15, 2016

    Ping again.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 16, 2016

    New changeset f086d6c9d9f6 by Raymond Hettinger in branch 'default':
    Issue bpo-25628: Make namedtuple "rename" and "verbose" parameters keyword-only.
    https://hg.python.org/cpython/rev/f086d6c9d9f6

    @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
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants