Skip to content

Commit 4dfefb8

Browse files
committed
Move _winapi import with other imports
1 parent 8d3ef98 commit 4dfefb8

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/_pyrepl/windows_console.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def __init__(self, err: int | None, descr: str | None = None) -> None:
6666
self.err = err
6767
self.descr = descr
6868

69+
try:
70+
import _winapi
71+
except ImportError:
72+
_winapi = None
73+
6974
# declare nt optional to allow None assignment on other platforms
7075
nt: types.ModuleType | None
7176
try:
@@ -696,6 +701,7 @@ def wait_for_event(self, timeout: float | None) -> bool:
696701
timeout = INFINITE
697702
else:
698703
timeout = int(timeout)
704+
assert _winapi is not None # to make mypy happy
699705
ret = _winapi.WaitForSingleObject(InHandle, timeout)
700706
if ret == WAIT_FAILED:
701707
raise WinError(get_last_error())
@@ -796,8 +802,7 @@ class INPUT_RECORD(Structure):
796802
STD_OUTPUT_HANDLE = -11
797803

798804
if sys.platform == "win32":
799-
import _winapi
800-
805+
assert _winapi is not None # to make mypy happy
801806
_KERNEL32 = WinDLL("kernel32", use_last_error=True)
802807

803808
GetConsoleScreenBufferInfo = _KERNEL32.GetConsoleScreenBufferInfo

0 commit comments

Comments
 (0)