-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Replace OrderedDict with regular dict in namedtuple's _asdict() method. #80045
Comments
Now that regular dicts are ordered and compact, it makes more sense for the _asdict() method to create a regular dict (as it did in its early days) rather than an OrderedDict. The regular dict is much smaller, much faster, and has a much cleaner looking repr. Historically we would go through a deprecation period for a possibly breaking change; however, it was considered more benefit to users and less disruptive to make the update directly. See the thread starting at: https://mail.python.org/pipermail/python-dev/2019-January/156150.html |
Thanks for doing this, Raymond! FYI, I found a couple of places where it still refers to OrderedDict:
[1] 0bb4bdf#diff-a2f0632ea84b755c7ef5b9bd291c7fdfR890 |
Also, there's a potentially misleading detail that you might consider correcting in the text. However, making it correct might make it slightly less clear, so it's a bit of a judgement call on how important it is to be explicit here. (FWIW, I think it's worth it to some extent.) The language reference doesn't guarantee that dictionaries are order-preserving (yet). [1] Therefore there can be (are?) Python implementations where dict isn't ordered. Users of those implementations may be confused by the docs (and docstring) saying the method returns a dict. This could be addressed by changing those places to say something like it returns an insertion-ordered mapping. The docs entry would also have an "CPython implementation detail" part saying it's actually a dict in CPython. Since "insertion-ordered mapping" isn't nearly as clear as "dict" (even if more correct), it may make more sense to simply say "dict". However, in that case I'd recommend at the very least to add a "CPython implementation detail" part to the docs entry which says in CPython it returns a dict, but in other implementations it may be some other order-preserving mapping. Honestly, after having written that the latter option seems more sensible. :) [1] https://docs.python.org/3.8/reference/datamodel.html#index-29 |
If you prefer, I'd be glad to open separate issues for either thing. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: