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

ENH: Move away from OrderedDict? #2033

Open
h-vetinari opened this issue Aug 11, 2024 · 3 comments
Open

ENH: Move away from OrderedDict? #2033

h-vetinari opened this issue Aug 11, 2024 · 3 comments

Comments

@h-vetinari
Copy link
Member

CPython has been guaranteeing insertion order in dictionaries since 3.6, so the use of OrderedDict looks a bit like an anachronism to me. It's also bothersome in the debug prints, because it'll print things in insertion order, rather than with alphabetical keys (so in large dumps it becomes impossible to verify if a given key is absent or present).

Not sure if there are any other reasons to keep it (other than inertia), but IMO this would be a nice cleanup.

@hmaarrfk
Copy link
Contributor

it seems its only used in a few locations.

Generally i find that some libraries do handle it in a special case when they serialize and deserialize into formats external to python.

@baszalmstra
Copy link
Member

Personally, I'm not against using OrderedDict because I like that it expresses a requirement on the dictionary instead of that behavior being implicit. This guarantees that it works regardless of which Python version (or interpreter) I use.

@h-vetinari
Copy link
Member Author

This guarantees that it works regardless of which Python version (or interpreter) I use.

It's part of the language spec since 3.7, so every conforming interpreter must implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants