Skip to content

Commit b3c4e87

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5a3d5ff commit b3c4e87

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed

mypy/dmypy_server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
from typing import Any, Callable, Final
2222
from typing_extensions import TypeAlias as _TypeAlias
2323

24-
from mypy import util
2524
import mypy.build
2625
import mypy.errors
2726
import mypy.main
27+
from mypy import util
2828
from mypy.dmypy_util import WriteToConn, receive, send
2929
from mypy.find_sources import InvalidSourceList, create_source_list
3030
from mypy.fscache import FileSystemCache
@@ -842,9 +842,15 @@ def pretty_messages(
842842
is_tty: bool = False,
843843
terminal_width: int | None = None,
844844
) -> list[str]:
845-
use_color = (True if util.should_force_color()
846-
else self.formatter.default_colored if self.options.color_output == "auto"
847-
else bool(self.options.color_output))
845+
use_color = (
846+
True
847+
if util.should_force_color()
848+
else (
849+
self.formatter.default_colored
850+
if self.options.color_output == "auto"
851+
else bool(self.options.color_output)
852+
)
853+
)
848854
fit_width = self.options.pretty and is_tty
849855
if fit_width:
850856
messages = self.formatter.fit_in_terminal(

mypy/main.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@ def main(
124124
install_types(formatter, options, non_interactive=options.non_interactive)
125125
return
126126

127-
use_color = (True if util.should_force_color()
128-
else formatter.default_colored if options.color_output == "auto"
129-
else bool(options.color_output))
127+
use_color = (
128+
True
129+
if util.should_force_color()
130+
else (
131+
formatter.default_colored
132+
if options.color_output == "auto"
133+
else bool(options.color_output)
134+
)
135+
)
130136

131137
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr, use_color)
132138

@@ -137,7 +143,9 @@ def main(
137143
install_types(formatter, options, after_run=True, non_interactive=True)
138144
fscache.flush()
139145
print()
140-
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr, use_color)
146+
res, messages, blockers = run_build(
147+
sources, options, fscache, t0, stdout, stderr, use_color
148+
)
141149
show_messages(messages, stderr, formatter, options, use_color)
142150

143151
if MEM_PROFILE:
@@ -243,8 +251,11 @@ def flush_errors(filename: str | None, new_messages: list[str], serious: bool) -
243251

244252

245253
def show_messages(
246-
messages: list[str], f: TextIO, formatter: util.FancyFormatter, options: Options,
247-
use_color: bool
254+
messages: list[str],
255+
f: TextIO,
256+
formatter: util.FancyFormatter,
257+
options: Options,
258+
use_color: bool,
248259
) -> None:
249260
for msg in messages:
250261
if use_color:
@@ -467,10 +478,16 @@ def __call__(
467478
parser._print_message(formatter.format_help(), self.stdout)
468479
parser.exit()
469480

481+
470482
# Coupled with the usage in define_options
471483
class ColorOutputAction(argparse.Action):
472-
def __call__(self, parser: argparse.ArgumentParser, namespace: argparse.Namespace,
473-
values: str | Sequence[Any] | None, option_string: str | None = None) -> None:
484+
def __call__(
485+
self,
486+
parser: argparse.ArgumentParser,
487+
namespace: argparse.Namespace,
488+
values: str | Sequence[Any] | None,
489+
option_string: str | None = None,
490+
) -> None:
474491
assert values in ("auto", None)
475492
print(f"{values=}")
476493
setattr(namespace, self.dest, True if values is None else "auto")
@@ -1016,16 +1033,13 @@ def add_invertible_flag(
10161033
nargs="?",
10171034
choices=["auto"],
10181035
help="Colorize error messages (inverse: --no-color-output). "
1019-
"Detects if to use color when option is omitted and --no-color-output "
1020-
"is not given, or when --color-output=auto",
1036+
"Detects if to use color when option is omitted and --no-color-output "
1037+
"is not given, or when --color-output=auto",
10211038
)
10221039
error_group.add_argument(
1023-
"--no-color-output",
1024-
dest="color_output",
1025-
action="store_false",
1026-
help=argparse.SUPPRESS,
1040+
"--no-color-output", dest="color_output", action="store_false", help=argparse.SUPPRESS
10271041
)
1028-
#error_group.set_defaults(color_output="auto")
1042+
# error_group.set_defaults(color_output="auto")
10291043
add_invertible_flag(
10301044
"--no-error-summary",
10311045
dest="error_summary",

mypy/test/test_color_output.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
from subprocess import run, PIPE
21
from functools import partial
2+
from subprocess import PIPE, run
33
from typing import Any
4+
45
import pytest
56

67
# TODO Would like help with this test, how do I make it runnable?
78

9+
810
def test(expect_color: bool, *args: Any, **kwargs: Any) -> None:
9-
res = run(*args, stdout=PIPE, stderr=PIPE, **kwargs) #type:ignore[call-overload]
10-
if "Found" not in res.stdout: #??
11+
res = run(*args, stdout=PIPE, stderr=PIPE, **kwargs) # type:ignore[call-overload]
12+
if "Found" not in res.stdout: # ??
1113
pytest.fail("Command failed to complete or did not detect type error")
12-
if expect_color: # Expect color control chars
14+
if expect_color: # Expect color control chars
1315
assert "<string>:1: error:" not in res.stdout
1416
assert "\nFound" not in res.stdout
15-
else: # Expect no color control chars
17+
else: # Expect no color control chars
1618
assert "<string>:1: error:" in res.stdout
1719
assert "\nFound" in res.stdout
1820

21+
1922
colored = partial(test, True)
2023
not_colored = partial(test, False)
2124

25+
2226
@pytest.mark.parametrize("command", ["mypy", "dmypy run --"])
2327
def test_color_output(command: str) -> None:
2428
# Note: Though we don't check stderr, capturing it is useful
@@ -28,7 +32,8 @@ def test_color_output(command: str) -> None:
2832
colored(f"{command} -c \"1+'a'\"", env={"MYPY_FORCE_COLOR": "1"})
2933
colored(f"{command} -c \"1+'a'\" --color-output")
3034
not_colored(f"{command} -c \"1+'a'\" --no-color-output")
31-
colored(f"{command} -c \"1+'a'\" --no-color-output", env={"MYPY_FORCE_COLOR": "1"}) #TODO
35+
colored(f"{command} -c \"1+'a'\" --no-color-output", env={"MYPY_FORCE_COLOR": "1"}) # TODO
36+
3237

3338
# TODO: Tests in the terminal (require manual testing?)
3439
"""
@@ -49,4 +54,4 @@ def test_color_output(command: str) -> None:
4954
mypy -c "1+'a'" --color-output
5055
mypy -c "1+'a'" --no-color-output
5156
set MYPY_FORCE_COLOR=
52-
"""
57+
"""

mypy/util.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,11 @@ def __init__(
609609
}
610610
else:
611611
if should_force_color():
612-
print("warning: failed to detect a suitable terminal color scheme "
613-
"but MYPY_FORCE_COLOR or FORCE_COLOR is set to on")
614-
self.colors = {
615-
"red": "",
616-
"green": "",
617-
"blue": "",
618-
"yellow": "",
619-
"none": "",
620-
}
612+
print(
613+
"warning: failed to detect a suitable terminal color scheme "
614+
"but MYPY_FORCE_COLOR or FORCE_COLOR is set to on"
615+
)
616+
self.colors = {"red": "", "green": "", "blue": "", "yellow": "", "none": ""}
621617

622618
def detect_terminal_colors(self, f_out: IO[str], f_err: IO[str]) -> bool:
623619
if sys.platform not in ("linux", "darwin", "win32", "emscripten"):

0 commit comments

Comments
 (0)