-
Notifications
You must be signed in to change notification settings - Fork 3
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
Ordered dicts #12
Comments
Yes, but Python >= 3.7, as for 3.6, the ordering is considered a "CPython implementation detail that you should not rely on". Do you agree? Further, the idea is to only allow that for those python versions and raise an error for lower versions (you have of course always the possibility of calling it with @SebastianJL: what's your opinion on that? |
True, but you might as well output it in the order given by the dict. If it's ordered everything is fine, if it's not then no problem either. Just skip the explicit re-ordering. |
Okay, but I cannot really see a (non-harmful) use-case for that. It will be implemented anyway to support the 3.7+ dicts, so technically it is not a problem to add, but for <=3.6 I can only think of two cases:
Can you think of a use-case where someone would use |
I agree that it would be a bad idea to develop software that relies on that dicts are ordered in python 3.6, but here I'm using a third-party module for one-time data analysis. Dicts don't have to be ordered to be used internally in that tool, but it happens to be convenient for me that they are. That way I can read a yaml-file, have the tool modify the contents and then dump it back without reordering. It just seems much more intrusive to explicitly choose to sort entries alphabetically rather than just using the ordering that is native to whatever python version you are running. |
I see! I would propose you to use the loader/dumber as following:
with Not a lot of extra-code, but works! |
That's what I do now, but since it's not my code that does the dumping I have to patch the other tool. A little cumbersome but fine. I guess it's this section in mapping = list(mapping.items())
try:
mapping = sorted(mapping)
except TypeError:
pass |
Alright, unfortunately I seem still to miss one point: if the dumping happens in the other tool, does it use Anyway, I would recommend you then to change the other code. It's a long-term investment and you're on the save side (being in the field of data-analysis myself, this is what I usually end up with doing). |
I understand the confusion :) The other tools uses |
Ah, got it! Yes, so I would go with the upstream fix in pyyaml. If that's fixed, it will work with If they don't do that (for whatever reason), then we'll may implement that here. Closing for now, feel free to reopen if it does not get fixed in pyyaml! |
the yaml/pyyaml#143 PR merge will probably take a bit longer. we had some problems with releasing a new version, and some api changes we need to make for the next version touch the same code as my PR |
@perlpunk thanks for letting us know! @rasmusagren We will soon release the 3.7 compatible version, which keeps the order with normal dicts as well. How does that sound to you? |
Finally also updated conda version, sorry for the delay! |
For Python>=3.6 normal dicts are now ordered as well. Could you please add so that their order is maintained as well? Thanks!
The text was updated successfully, but these errors were encountered: