Skip to content

Commit 40f4d66

Browse files
authored
Improve color and terminal width overrides (python#7674)
1 parent 33e3558 commit 40f4d66

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

mypy/dmypy/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,9 @@ def request(status_file: str, command: str, *, timeout: Optional[int] = None,
468468
args['command'] = command
469469
# Tell the server whether this request was initiated from a human-facing terminal,
470470
# so that it can format the type checking output accordingly.
471-
args['is_tty'] = sys.stdout.isatty()
472-
args['terminal_width'] = get_terminal_width()
471+
args['is_tty'] = sys.stdout.isatty() or int(os.getenv('MYPY_FORCE_COLOR', '0')) > 0
472+
args['terminal_width'] = (int(os.getenv('MYPY_FORCE_TERMINAL_WIDTH', '0')) or
473+
get_terminal_width())
473474
bdata = json.dumps(args).encode('utf8')
474475
_, name = get_status(status_file)
475476
try:

mypy/dmypy_server.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ def run_command(self, command: str, data: Dict[str, object]) -> Dict[str, object
265265
# Only the above commands use some error formatting.
266266
del data['is_tty']
267267
del data['terminal_width']
268-
elif int(os.getenv('MYPY_FORCE_COLOR', '0')):
269-
data['is_tty'] = True
270268
return method(self, **data)
271269

272270
# Command functions (run in the server via RPC).

mypy/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ def style(self, text: str, color: Literal['red', 'green', 'blue', 'yellow', 'non
568568
def fit_in_terminal(self, messages: List[str],
569569
fixed_terminal_width: Optional[int] = None) -> List[str]:
570570
"""Improve readability by wrapping error messages and trimming source code."""
571-
width = fixed_terminal_width or get_terminal_width()
571+
width = (fixed_terminal_width or int(os.getenv('MYPY_FORCE_TERMINAL_WIDTH', '0')) or
572+
get_terminal_width())
572573
new_messages = messages.copy()
573574
for i, error in enumerate(messages):
574575
if ': error:' in error:

0 commit comments

Comments
 (0)
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