This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Can namedtuple._asdict return a regular dict instead of OrderedDict?
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, rhettinger, selik, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-05-11 03:31 by selik, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6772 closed selik, 2018-05-12 17:07
Messages (6)
msg316387 - (view) Author: Michael Selik (selik) * Date: 2018-05-11 03:31
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.
msg316397 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-05-11 14:24
This would have to go through a deprecation cycle, but it would be a nice improvement (faster, cleaner, and consistent with data classes).
msg316432 - (view) Author: Michael Selik (selik) * Date: 2018-05-12 17:08
Is this warning what you had in mind?
msg316621 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-15 05:26
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).
msg317456 - (view) Author: Michael Selik (selik) * Date: 2018-05-23 21:04
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?
msg355131 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-10-22 15:03
we can close this (raymond resolved this in bpo-35864)
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77644
2019-10-22 15:40:24rhettingersetstatus: open -> closed
resolution: out of date
stage: patch review -> resolved
2019-10-22 15:03:49BTaskayasetnosy: + BTaskaya
messages: + msg355131
2018-05-23 21:04:05seliksetmessages: + msg317456
2018-05-15 05:26:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg316621
2018-05-12 17:08:22seliksetmessages: + msg316432
2018-05-12 17:07:57seliksetkeywords: + patch
stage: patch review
pull_requests: + pull_request6461
2018-05-11 14:24:27rhettingersetassignee: rhettinger ->
messages: + msg316397
components: + Library (Lib)
2018-05-11 04:19:51serhiy.storchakasetassignee: rhettinger

nosy: + rhettinger
2018-05-11 04:11:22rhettingersetversions: - Python 3.7
2018-05-11 03:31:03selikcreate