Skip to content

Commit 76c16a4

Browse files
authored
[dmypy] special case stdout and stderr in show_stats too (#15881)
When running dmypy, the communication between client and server is via JSON. The JSON contains the keys "out" and "err" for the actual result of "check" command, and "stdout" and "stderr" for the any other stdout and stderr text. show_stats is shown when running with --verbose. It's meant to show other keys in the JSON response, like python version or time taken. It already had some special casing to only show 1 line of text for "out" and "err". Let's add "stdout" and "stderr" to the special casing as well. Also, let's show the remaining number of characters as well. Finally, added a comment in code about stdout, stderr, out, err and how we shouldn't confuse them. (I did) Some more cleanup is needed in this area of the codebase, but will be a separate PR. show_stats outputs something like this: ``` err : out : analytics/scripts/presto/report_query_lo ... 100 more characters platform : linux python_version : 3_9 roundtrip_time : 31.996 status : 2 stderr : \nLOG: Mypy Version: 1.6.0+de ... 50186630 more characters stdout : ```
1 parent 14418bc commit 76c16a4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mypy/dmypy/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ def check_output(
562562
sys.stdout.write(out)
563563
sys.stdout.flush()
564564
sys.stderr.write(err)
565+
sys.stderr.flush()
565566
if verbose:
566567
show_stats(response)
567568
if junit_xml:
@@ -588,13 +589,14 @@ def check_output(
588589

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

599601

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

0 commit comments

Comments
 (0)