Skip to content
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

[dmypy] special case stdout and stderr in show_stats too #15881

Merged
merged 1 commit into from
Aug 16, 2023
Merged
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
12 changes: 8 additions & 4 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ def check_output(
sys.stdout.write(out)
sys.stdout.flush()
sys.stderr.write(err)
sys.stderr.flush()
if verbose:
show_stats(response)
if junit_xml:
Expand All @@ -588,13 +589,14 @@ def check_output(

def show_stats(response: Mapping[str, object]) -> None:
for key, value in sorted(response.items()):
if key not in ("out", "err"):
print("%-24s: %10s" % (key, "%.3f" % value if isinstance(value, float) else value))
else:
if key in ("out", "err", "stdout", "stderr"):
# Special case text output to display just 40 characters of text
value = repr(value)[1:-1]
if len(value) > 50:
value = value[:40] + " ..."
value = f"{value[:40]} ... {len(value)-40} more characters"
print("%-24s: %s" % (key, value))
continue
print("%-24s: %10s" % (key, "%.3f" % value if isinstance(value, float) else value))


@action(hang_parser)
Expand Down Expand Up @@ -668,6 +670,8 @@ def request(
# TODO: Other errors, e.g. ValueError, UnicodeError
else:
# Display debugging output written to stdout/stderr in the server process for convenience.
# This should not be confused with "out" and "err" fields in the response.
# Those fields hold the output of the "check" command, and are handled in check_output().
stdout = response.get("stdout")
if stdout:
sys.stdout.write(stdout)
Expand Down