Skip to content

Commit 10ca3ab

Browse files
committed
Merge branch 'color-output-option' of https://github.com/studyingegret/mypy into color-output-option
2 parents bd4460d + 5879267 commit 10ca3ab

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

mypy/dmypy_server.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,19 @@ def __init__(self, options: Options, status_file: str, timeout: int | None = Non
199199
# (details in https://github.com/python/mypy/issues/4492)
200200
options.local_partial_types = True
201201
self.status_file = status_file
202-
202+
203203
# Type annotation needed for mypy (Pyright understands this)
204204
use_color: bool | Literal["auto"] = (
205205
True
206206
if util.should_force_color()
207-
else (
208-
"auto"
209-
if options.color_output == "auto"
210-
else cast(bool, options.color_output)
211-
)
207+
else ("auto" if options.color_output == "auto" else cast(bool, options.color_output))
212208
)
213209

214210
# Since the object is created in the parent process we can check
215211
# the output terminal options here.
216-
self.formatter = FancyFormatter(sys.stdout, sys.stderr, options.hide_error_codes,
217-
color_request=use_color)
212+
self.formatter = FancyFormatter(
213+
sys.stdout, sys.stderr, options.hide_error_codes, color_request=use_color
214+
)
218215

219216
def _response_metadata(self) -> dict[str, str]:
220217
py_version = f"{self.options.python_version[0]}_{self.options.python_version[1]}"

mypy/main.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Sequence
1212
from gettext import gettext
1313
from io import TextIOWrapper
14-
from typing import IO, TYPE_CHECKING, Any, Final, Literal, NoReturn, TextIO, Union, cast
14+
from typing import IO, TYPE_CHECKING, Any, Final, Literal, NoReturn, TextIO, cast
1515

1616
from mypy import build, defaults, state, util
1717
from mypy.config_parser import (
@@ -94,15 +94,15 @@ def main(
9494
use_color: bool | Literal["auto"] = (
9595
True
9696
if util.should_force_color()
97-
else (
98-
"auto"
99-
if options.color_output == "auto"
100-
else cast(bool, options.color_output)
101-
)
97+
else ("auto" if options.color_output == "auto" else cast(bool, options.color_output))
10298
)
10399

104100
formatter = util.FancyFormatter(
105-
stdout, stderr, options.hide_error_codes, hide_success=bool(options.output), color_request=use_color
101+
stdout,
102+
stderr,
103+
options.hide_error_codes,
104+
hide_success=bool(options.output),
105+
color_request=use_color,
106106
)
107107

108108
if options.allow_redefinition_new and not options.local_partial_types:
@@ -198,8 +198,11 @@ def run_build(
198198
use_color: bool | Literal["auto"],
199199
) -> tuple[build.BuildResult | None, list[str], bool]:
200200
formatter = util.FancyFormatter(
201-
stdout, stderr, options.hide_error_codes, hide_success=bool(options.output),
202-
color_request=use_color
201+
stdout,
202+
stderr,
203+
options.hide_error_codes,
204+
hide_success=bool(options.output),
205+
color_request=use_color,
203206
)
204207

205208
messages = []

mypy/util.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import time
1313
from collections.abc import Container, Iterable, Sequence, Sized
1414
from importlib import resources as importlib_resources
15-
from typing import IO, TYPE_CHECKING, Any, Callable, Final, Literal, TypeVar, cast
15+
from typing import IO, Any, Callable, Final, Literal, TypeVar
1616

1717
orjson: Any
1818
try:
@@ -593,8 +593,12 @@ class FancyFormatter:
593593
"""
594594

595595
def __init__(
596-
self, f_out: IO[str], f_err: IO[str], hide_error_codes: bool, hide_success: bool = False,
597-
color_request: bool | Literal["auto"] = "auto"
596+
self,
597+
f_out: IO[str],
598+
f_err: IO[str],
599+
hide_error_codes: bool,
600+
hide_success: bool = False,
601+
color_request: bool | Literal["auto"] = "auto",
598602
) -> None:
599603
self.hide_error_codes = hide_error_codes
600604
self.hide_success = hide_success
@@ -729,7 +733,7 @@ def style(
729733
start += self.UNDER
730734
if dim:
731735
start += self.DIM
732-
#if TYPE_CHECKING:
736+
# if TYPE_CHECKING:
733737
# reveal_type(self.colors)
734738
return start + self.colors[color] + text + self.NORMAL
735739

0 commit comments

Comments
 (0)