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

Can namedtuple._asdict return a regular dict instead of OrderedDict? #77644

Closed
selik mannequin opened this issue May 11, 2018 · 6 comments
Closed

Can namedtuple._asdict return a regular dict instead of OrderedDict? #77644

selik mannequin opened this issue May 11, 2018 · 6 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@selik
Copy link
Mannequin

selik mannequin commented May 11, 2018

BPO 33463
Nosy @rhettinger, @serhiy-storchaka, @selik, @isidentical
PRs
  • bpo-33463: _asdict --> dict, not OrderedDict #6772
  • 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 = None
    closed_at = <Date 2019-10-22.15:40:24.670>
    created_at = <Date 2018-05-11.03:31:03.295>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Can namedtuple._asdict return a regular dict instead of OrderedDict?'
    updated_at = <Date 2019-10-22.15:40:24.668>
    user = 'https://github.com/selik'

    bugs.python.org fields:

    activity = <Date 2019-10-22.15:40:24.668>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-10-22.15:40:24.670>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2018-05-11.03:31:03.295>
    creator = 'selik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33463
    keywords = ['patch']
    message_count = 6.0
    messages = ['316387', '316397', '316432', '316621', '317456', '355131']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'serhiy.storchaka', 'selik', 'BTaskaya']
    pr_nums = ['6772']
    priority = 'normal'
    resolution = 'out of date'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue33463'
    versions = ['Python 3.8']

    @selik
    Copy link
    Mannequin Author

    selik mannequin commented May 11, 2018

    Since the basic dict is now keeping insertion order, can we switch namedtuple._asdict to return a basic dict? Other than OrderedDict.move_to_end and the repr, I believe there is no compatibility issue.

    @selik selik mannequin added 3.7 (EOL) end of life 3.8 only security fixes type-feature A feature request or enhancement labels May 11, 2018
    @rhettinger rhettinger removed the 3.7 (EOL) end of life label May 11, 2018
    @rhettinger
    Copy link
    Contributor

    This would have to go through a deprecation cycle, but it would be a nice improvement (faster, cleaner, and consistent with data classes).

    @rhettinger rhettinger added the stdlib Python modules in the Lib dir label May 11, 2018
    @rhettinger rhettinger removed their assignment May 11, 2018
    @selik
    Copy link
    Mannequin Author

    selik mannequin commented May 12, 2018

    Is this warning what you had in mind?
    #6772

    @serhiy-storchaka
    Copy link
    Member

    DeprecationWarning is for things that will be removed. This is a sign: don't use this feature, rewrite you code so that doesn't use it, otherwise it will be broken in future versions.

    FutureVersion is for things that work now and will work in future, but will change its behavior in future. This is a sign: be prepared that your code will be broken in a way that will lead to returning a wrong result instead of failing. It is better to use alternatives until this feature be stabilized.

    Both warnings are not well appropriate here. They are too loud, and there are no good alternatives to _asdict(). Most users don't care about additional methods or performance guaranties of the result, thy just need a mapping, and it is desirable if it preserves the order of named tuple fields. I think it would be better to not add a runtime warning. Instead you can add a warning in the documentation in previous versions (just to the versionchanged directive that says when _dict() started returning an OrderedDict).

    @selik
    Copy link
    Mannequin Author

    selik mannequin commented May 23, 2018

    I changed the PR to simply replace OrderedDict with dict. For the docs warnings, if I'm understanding correctly, those should be separate pulls for older branches?

    @isidentical
    Copy link
    Sponsor Member

    we can close this (raymond resolved this in bpo-35864)

    @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
    3.8 only security fixes 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