Skip to content

Support debug prints in mypy daemon #13769

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

Merged
merged 1 commit into from
Sep 29, 2022
Merged
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
4 changes: 4 additions & 0 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ def request(
return {"error": str(err)}
# TODO: Other errors, e.g. ValueError, UnicodeError
else:
# Display debugging output written to stdout in the server process for convenience.
stdout = response.get("stdout")
if stdout:
sys.stdout.write(stdout)
return response


Expand Down
4 changes: 4 additions & 0 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def serve(self) -> None:
while True:
with server:
data = receive(server)
debug_stdout = io.StringIO()
sys.stdout = debug_stdout
resp: dict[str, Any] = {}
if "command" not in data:
resp = {"error": "No command found in request"}
Expand All @@ -230,8 +232,10 @@ def serve(self) -> None:
tb = traceback.format_exception(*sys.exc_info())
resp = {"error": "Daemon crashed!\n" + "".join(tb)}
resp.update(self._response_metadata())
resp["stdout"] = debug_stdout.getvalue()
server.write(json.dumps(resp).encode("utf8"))
raise
resp["stdout"] = debug_stdout.getvalue()
try:
resp.update(self._response_metadata())
server.write(json.dumps(resp).encode("utf8"))
Expand Down