Skip to content

Commit b65e27a

Browse files
committed
Fix CI
1 parent 4607277 commit b65e27a

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

mypy/util.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
except ImportError:
2929
CURSES_ENABLED = False
3030

31-
IS_WIN: Final = sys.platform == "win32"
32-
3331
T = TypeVar("T")
3432

3533
TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed")
@@ -606,7 +604,7 @@ def __init__(
606604
if not should_force_color() and (not f_out.isatty() or not f_err.isatty()):
607605
self.dummy_term = True
608606
return
609-
if IS_WIN:
607+
if sys.platform == "win32":
610608
self.dummy_term = not self.initialize_win_colors()
611609
elif sys.platform == "emscripten":
612610
self.dummy_term = not self.initialize_vt100_colors()
@@ -640,32 +638,34 @@ def initialize_win_colors(self) -> bool:
640638
# Windows ANSI escape sequences are only supported on Threshold 2 and above.
641639
# we check with an assert at runtime and an if check for mypy, as asserts do not
642640
# yet narrow platform
643-
assert IS_WIN, "Running not on Windows"
644-
winver = sys.getwindowsversion()
645-
if (
646-
winver.major < MINIMUM_WINDOWS_MAJOR_VT100
647-
or winver.build < MINIMUM_WINDOWS_BUILD_VT100
648-
):
649-
return False
650-
import ctypes
651-
652-
kernel32 = ctypes.windll.kernel32
653-
ENABLE_PROCESSED_OUTPUT = 0x1
654-
ENABLE_WRAP_AT_EOL_OUTPUT = 0x2
655-
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
656-
STD_OUTPUT_HANDLE = -11
657-
kernel32.SetConsoleMode(
658-
kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
659-
ENABLE_PROCESSED_OUTPUT
660-
| ENABLE_WRAP_AT_EOL_OUTPUT
661-
| ENABLE_VIRTUAL_TERMINAL_PROCESSING,
662-
)
663-
self.initialize_vt100_colors()
641+
assert sys.platform == "win32", "Running not on Windows"
642+
if sys.platform == "win32": # needed to find win specific sys apis
643+
winver = sys.getwindowsversion()
644+
if (
645+
winver.major < MINIMUM_WINDOWS_MAJOR_VT100
646+
or winver.build < MINIMUM_WINDOWS_BUILD_VT100
647+
):
648+
return False
649+
import ctypes
650+
651+
kernel32 = ctypes.windll.kernel32
652+
ENABLE_PROCESSED_OUTPUT = 0x1
653+
ENABLE_WRAP_AT_EOL_OUTPUT = 0x2
654+
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
655+
STD_OUTPUT_HANDLE = -11
656+
kernel32.SetConsoleMode(
657+
kernel32.GetStdHandle(STD_OUTPUT_HANDLE),
658+
ENABLE_PROCESSED_OUTPUT
659+
| ENABLE_WRAP_AT_EOL_OUTPUT
660+
| ENABLE_VIRTUAL_TERMINAL_PROCESSING,
661+
)
662+
self.initialize_vt100_colors()
664663
return True
665664

666665
def initialize_unix_colors(self) -> bool:
667666
"""Return True if initialization was successful and we can use colors, False otherwise"""
668-
if IS_WIN or not CURSES_ENABLED:
667+
is_win = sys.platform == "win32"
668+
if is_win or not CURSES_ENABLED:
669669
return False
670670
try:
671671
# setupterm wants a fd to potentially write an "initialization sequence".

0 commit comments

Comments
 (0)