Skip to content

Commit 807f022

Browse files
committed
More changes
1 parent 433159b commit 807f022

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

mypy/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ def main(
124124
install_types(formatter, options, non_interactive=options.non_interactive)
125125
return
126126

127-
use_color = (formatter.default_colored if options.color_output == "auto"
127+
use_color = (True if util.should_force_color()
128+
else formatter.default_colored if options.color_output == "auto"
128129
else bool(options.color_output))
129130

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

mypy/test/test_color_output.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,45 @@
44

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

7+
def test(expect_color: bool, *args: Any, **kwargs: Any) -> None:
8+
res = run(*args, stdout=PIPE, stderr=PIPE, **kwargs)
9+
if expect_color: # Expect color control chars
10+
assert "<string>:1: error:" not in res.stdout
11+
assert "\nFound" not in res.stdout
12+
else: # Expect no color control chars
13+
assert "<string>:1: error:" in res.stdout
14+
assert "\nFound" in res.stdout
15+
16+
colored = partial(test, True)
17+
not_colored = partial(test, False)
18+
719
def test_color_output() -> None:
820
# Note: Though we don't check stderr, capturing it is useful
921
# because it provides traceback if mypy crashes due to exception
1022
# and pytest reveals it upon failure (?)
11-
def test(expect_color: bool, *args: Any, **kwargs: Any) -> None:
12-
res = run(*args, stdout=PIPE, stderr=PIPE, **kwargs)
13-
if expect_color: # Expect color control chars
14-
assert "<string>:1: error:" not in res.stdout
15-
assert "]\nFound" not in res.stdout
16-
else: # Expect no color control chars
17-
assert "<string>:1: error:" in res.stdout
18-
assert "]\nFound" in res.stdout
19-
colored = partial(test, True)
20-
not_colored = partial(test, False)
2123
not_colored("mypy -c \"1+'a'\"")
2224
colored("mypy -c \"1+'a'\"", env={"MYPY_FORCE_COLOR": "1"})
2325
colored("mypy -c \"1+'a'\" --color-output")
2426
not_colored("mypy -c \"1+'a'\" --no-color-output")
25-
colored("mypy -c \"1+'a'\" --no-color-output", env={"MYPY_FORCE_COLOR": "1"})
27+
colored("mypy -c \"1+'a'\" --no-color-output", env={"MYPY_FORCE_COLOR": "1"}) #TODO
28+
29+
# TODO: Tests in the terminal (require manual testing?)
30+
"""
31+
In the terminal:
32+
colored: mypy -c "1+'a'"
33+
colored: mypy -c "1+'a'" --color-output
34+
not colored: mypy -c "1+'a'" --no-color-output
35+
colored: mypy -c "1+'a'" --color-output (with MYPY_FORCE_COLOR=1)
36+
colored: mypy -c "1+'a'" --no-color-output (with MYPY_FORCE_COLOR=1)
37+
38+
To test, save this as a .bat and run in a Windows terminal (I don't know the Unix equivalent):
2639
27-
# TODO: Tests in the terminal (require manual testing?)
40+
set MYPY_FORCE_COLOR=
41+
mypy -c "1+'a'"
42+
mypy -c "1+'a'" --color-output
43+
mypy -c "1+'a'" --no-color-output
44+
set MYPY_FORCE_COLOR=1
45+
mypy -c "1+'a'" --color-output
46+
mypy -c "1+'a'" --no-color-output
47+
set MYPY_FORCE_COLOR=
48+
"""

mypy/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ def __init__(
609609
}
610610
else:
611611
if should_force_color():
612-
print("warning: failed to detect a suitable color scheme "
613-
"but MYPY_FORCE_COLOR or FORCE_COLOR is enabled")
612+
print("warning: failed to detect a suitable terminal color scheme "
613+
"but MYPY_FORCE_COLOR or FORCE_COLOR is set to on")
614614
self.colors = {
615615
"red": "",
616616
"green": "",

0 commit comments

Comments
 (0)