-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Open
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement
Description
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.
>>> t = {'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}}
>>> pprint(t, indent=4, some_parameter=True)
{
"a": 2,
"b": {
"x": 3,
"y": {
"t1": 4,
"t2": 5
}
}
}
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
Dobatymo, harshit-singhania2000, mollen, Wulian233, stodoran and 3 more
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtype-featureA feature request or enhancementA feature request or enhancement