-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add indent parameter to edn_format.dumps() #70
Add indent parameter to edn_format.dumps() #70
Conversation
Using the script from @bfontaine from PR #64 (just one run because I am lazy): This branch without indent:
This branch with indent:
Master:
So yeah, a slightly overhead, however it does not seem that bad. WDYT @swaroopch ? |
Awesome! 🙌 FYI I generated 100,000 random EDN structures which I dumped with |
@thiagokokada Will follow up this week. |
@thiagokokada This is a really nice implementation! 👍 for writing the tests.
Thank you! |
|
|
One minor optimization that may help would be to store |
I applied the small optimization from @bfontaine anyway and add the docstrings asked by @swaroopch. Now about the
There really doesn't seem to have much difference. Actually even using string concat (that should be slower) there isn't much difference in performance, at least using the benchmark from @bfontaine. I think the current code is more idiomatic Python too and it also avoids an import, so I prefer it as current it is. WDYT? |
Thank you @thiagokokada ! |
This adds a pretty printer similar to
json.dumps(indent=<int>)
. However, it does not follow Clojure formatting guidelines, instead formatting in a way more common to users from other languages like Python.So it will convert this:
To this:
Instead of this:
This should be already better than the current status quo (that is, no pretty printer at all).
Should fix issue #39 (unless the author of the issue wanted a more Clojure-like pretty printer).
Alternative implementation of PR #64. It fixes all issues found by @bfontaine, and also this approach is simpler. However, different of the older approach this one also brings change in the non-indent flow, and it may be slower (however I think the difference will be insignificant).