Skip to content

Fix mypy pretty output within a pty #8145

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 2 commits into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix mypy pretty output within a pty
  • Loading branch information
asottile committed Dec 13, 2019
commit 9dccccaf68924a89f5d01d2a76a671a5dc7f3918
12 changes: 12 additions & 0 deletions mypy/test/testutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
from unittest import mock, TestCase

from mypy.util import get_terminal_width


class TestGetTerminalSize(TestCase):
def test_get_terminal_size_in_pty_defaults_to_80(self) -> None:
# when run using a pty, `os.get_terminal_size()` returns `0, 0`
ret = os.terminal_size((0, 0))
with mock.patch.object(os, 'get_terminal_size', return_value=ret):
assert get_terminal_width() == 80
5 changes: 4 additions & 1 deletion mypy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,12 @@ def get_terminal_width() -> int:
"""Get current terminal width if possible, otherwise return the default one."""
try:
cols, _ = os.get_terminal_size()
return cols
except OSError:
return DEFAULT_COLUMNS
else:
if cols == 0:
return DEFAULT_COLUMNS
return cols


def soft_wrap(msg: str, max_len: int, first_offset: int,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy