-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
pprint with compact indent #112632
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
Comments
Hey! would love to contribute here, can this issue be assigned to me? |
Any updates on this? I'm left scratching my head wondering why this feature doesn't already exist, I mean the current output for a large nested dictionary with If it is a bandwidth thing I'd be happy to try and contribute here if somebody could give me some pointers. |
@stodoran Please, feel free to work on this! You might find the devguide useful: https://devguide.python.org/ |
@tomasr8 I did have two questions
|
I would recommend first opening a DPO thread. There are alternatives such as I don't think
The past 10 years have seen small improvements and changes. The same can be said for
We should first open a DPO thread before accepting such feature IMO. However, anyone can present a PoC so that we can estimate how complex the addition would be and whether we want to keep it in the standard library or not. |
As a counter point, pprint can already do indents, this is just about adding newlines here and there, so I think the implementation shouldn't be that complex (famous last words 😅 ) |
If it's not that complex, I wouldn't mind skipping the DPO discussion. However it must really be simple! But now I see value in this because:
This one is really not a nice way to read stuff.. Maybe we could change the meaning of |
I may have been overthinking it, the solution was not that complex. Here is a basic implementation. Please let me know how I can improve it, this is my first time contributing. Also, I didn't include a fix for this in my PR but I discovered a bug during testing; |
Feature or enhancement
Proposal:
Add a new parameter to the pprint function that inserts a newline character (\n) after the opening parenthesis, and sets the indent to level * indent. With this parameter, pprint will format nested objects in a manner similar to how formatters like Black or Ruff format them.
With this change, pprint will print in a more width-compact manner, making it easier to read and copy-page pretty printed object to codebase wich follows similar formmating rule.
This feature was hevily inspired by this question on Stackoverflow
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
pprint
#129274The text was updated successfully, but these errors were encountered: