Skip to content

bpo-43451: Render inspect function arguments one-per-line when they exceed a maximum length #24802

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,13 @@ def __str__(self):
# flag was not reset to 'False'
result.append('/')

rendered = '({})'.format(', '.join(result))
# If arguments are liable exceed to some representative line width,
# write one per line with an indent. Improves pydoc rendering of
# complex annotations.
if (sum(map(len, result)) + (2 * len(result))) > 150:
rendered = '(\n {}\n)'.format(',\n '.join(result))
else:
rendered = '({})'.format(', '.join(result))

if self.return_annotation is not _empty:
anno = formatannotation(self.return_annotation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Wrap long arguments lists in ``pydoc`` terminal output.