Skip to content

Commit 792ba28

Browse files
committed
Fix CI
1 parent f45652d commit 792ba28

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

mypy/stubgen.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,7 @@ def is_blacklisted_path(path: str) -> bool:
15071507

15081508

15091509
def normalize_path_separators(path: str) -> str:
1510-
if sys.platform == "win32":
1511-
return path.replace("\\", "/")
1512-
return path
1510+
return path.replace("\\", "/") if sys.platform == "win32" else path
15131511

15141512

15151513
def collect_build_targets(

mypy/util.py

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

31+
IS_WIN: Final = sys.platform == "win32"
32+
3133
T = TypeVar("T")
3234

3335
TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed")
@@ -571,8 +573,7 @@ def hash_digest(data: bytes) -> str:
571573

572574
def parse_gray_color(cup: bytes) -> str:
573575
"""Reproduce a gray color in ANSI escape sequence"""
574-
if sys.platform == "win32":
575-
assert False, "curses is not available on Windows"
576+
assert sys.platform != "win32", "curses is not available on Windows"
576577
set_color = "".join([cup[:-1].decode(), "m"])
577578
gray = curses.tparm(set_color.encode("utf-8"), 1, 9).decode()
578579
return gray
@@ -605,7 +606,7 @@ def __init__(
605606
if not should_force_color() and (not f_out.isatty() or not f_err.isatty()):
606607
self.dummy_term = True
607608
return
608-
if sys.platform == "win32":
609+
if IS_WIN:
609610
self.dummy_term = not self.initialize_win_colors()
610611
elif sys.platform == "emscripten":
611612
self.dummy_term = not self.initialize_vt100_colors()
@@ -639,34 +640,32 @@ def initialize_win_colors(self) -> bool:
639640
# Windows ANSI escape sequences are only supported on Threshold 2 and above.
640641
# we check with an assert at runtime and an if check for mypy, as asserts do not
641642
# yet narrow platform
642-
assert sys.platform == "win32"
643-
if sys.platform == "win32":
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()
664-
return True
665-
return False
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()
664+
return True
666665

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

0 commit comments

Comments
 (0)