-
Notifications
You must be signed in to change notification settings - Fork 518
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
Allow to turn off sorting keys in Dumper #143
Conversation
Travis tests are failing. I need to find out how to run the tests locally. Any hints for a python beginner? |
thanks @ingydotnet for |
I started to write a test for this. Will probably push it tomorrow |
06aa073
to
4a74967
Compare
rebased to master, tests now including 3.7-dev, and 2.6 is passing |
Rebased to current master, squashed commits. |
This is great! Looking forward to this being merged! 🚀 |
Any progress on this PR? |
@jasonrhaas I'm hoping this eventually gets merged to source but for now oyaml does the trick. |
Please, merge this. I've spent countless hours trying to work around this. |
I too am interested is this. Would like to use in a feature where a tool slightly modifies YAML files that are checked into source. Would love the edits to look slight. The YAML files are initially ordered by hand, to expecting keys to be alphanumerically sorted is unrealistic; humans tend to group keys by purpose and/or importance. |
Dear Perl punk (since you seem the only maintainer left here), leaving "sorted" by default is still wrong. Sorting the keys is a superfluous operation wrt the YAML spec. It is also anti-pythonic, and goes against the most basic programming principle of not doing needless things. Now it is obvious from the comments that devs using PyYAML for actual work are negatively impacted by this anti-feature. Like in my case, it renders this library unusable for their projects. Whoever wants the keys sorted should be doing it at the .yaml source. That is the whole point of defining interfaces in YAML. "Backwards compatibility" feels like a weak excuse here. Please listen to the community and be honest here. |
@gatopeich this is a pull request. It's a suggestion. I don't decide anything, I can just help making decisions. I agree that for python versions that keep the original order, Would it make sense to make the default depend on the python version? |
Would it make sense to make the default depend on the python version? Okay. Then let's apply same default as for |
Can this be merged now? |
If you're concerned about portability, it's okay to have it default to (I think having a package changing its behavior after seemingly transparent Python upgrade breaks the principle of least astonishment, although personally I too would like to see it default to |
Closing, recreated based on current master: #254 |
This was introduced by yaml/pyyaml#143
This was introduced by yaml/pyyaml#143
This was introduced by yaml/pyyaml#143
See issue #110
This allows to do:
The default is True because of backwards compatibility.
This can be useful for python >= 3.7 to preserve key order. Also not sorting will probably be faster.
I didn't add a test because I'm not yet familiar with testing in python
and couldn't find out how the pyyaml test suite works.
Also i don't know where to document that.