[Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict
Nathaniel Smith
njs at pobox.com
Thu Jan 31 16:25:53 EST 2019
More information about the Python-Dev mailing list
Thu Jan 31 16:25:53 EST 2019
- Previous message (by thread): [Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict
- Next message (by thread): [Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Jan 31, 2019, 05:26 Nick Coghlan <ncoghlan at gmail.com wrote: > On Thu, 31 Jan 2019 at 16:40, Glenn Linderman <v+python at g.nevcal.com> > wrote: > >> On 1/30/2019 8:45 PM, Raymond Hettinger wrote: > >>> On Jan 30, 2019, at 3:41 PM, Glenn Linderman <v+python at g.nevcal.com> > wrote: > >>> Would it be practical to add deprecated methods to regular dict for > the OrderedDict reordering methods that raise with an error suggesting "To > use this method, convert dict to OrderedDict." (or some better wording). > >> That's an interesting idea. Regular dicts aren't well suited to the > reordering operations (like lists, repeated inserts at the front of the > sequence wouldn't be performant relative to OrderedDict which uses > double-linked lists internally). My instinct is to leave regular dicts > alone so that they can focus on their primary task (being good a fast > lookups). > > My goal was just to give a meaningful error message if someone misses > the implications in What's New, and has code that actually does expect > named_tuple.as_dict to have the ordering operations. > > The downside of doing that is that automated code introspection tools > don't know that the methods don't really exist, they just see the > method names in the type dictionary and offer them up for code > completion. > > So in this case, the extra runtime check isn't worth the cost of > breaking static code analysis and other forms of introspection. > It's technically possible for attributes to do something custom when accessed, without appearing in __dir__. I don't know if that's a useful technique in this case, but sometimes it is. -n -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20190131/b8f1641f/attachment.html>
- Previous message (by thread): [Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict
- Next message (by thread): [Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list