Issue 33463: Can namedtuple._asdict return a regular dict instead of OrderedDict? (original) (raw)

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? https://github.com/python/cpython/pull/6772
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)
History
Date User Action Args
2022-04-11 14:59:00 admin set github: 77644
2019-10-22 15:40:24 rhettinger set status: open -> closedresolution: out of datestage: patch review -> resolved
2019-10-22 15:03:49 BTaskaya set nosy: + BTaskayamessages: +
2018-05-23 21:04:05 selik set messages: +
2018-05-15 05:26:08 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2018-05-12 17:08:22 selik set messages: +
2018-05-12 17:07:57 selik set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest6461>
2018-05-11 14:24:27 rhettinger set assignee: rhettinger -> messages: + components: + Library (Lib)
2018-05-11 04:19:51 serhiy.storchaka set assignee: rhettingernosy: + rhettinger
2018-05-11 04:11:22 rhettinger set versions: - Python 3.7
2018-05-11 03:31:03 selik create