From 0cfe8cd5c9d4e45994b68b25b4f285622fc45235 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 17 Nov 2026 13:51:58 +0100 Subject: [PATCH] refactor: read msvcrt as the runtime holds it --- install.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/install.py b/install.py index 50625203f..8fa99533b 100644 --- a/install.py +++ b/install.py @@ -8714,9 +8714,13 @@ def _claim_partial(path: Path) -> BinaryIO | None: handle = os.fdopen(os.open(path, flags, 0o644), "r+b") try: if os.name == "nt": - import msvcrt + import importlib - msvcrt.locking(handle.fileno(), msvcrt.LK_NBLCK, 1) + # typeshed declares msvcrt for win32 only: the module is read + # as the runtime holds it. + msvcrt = importlib.import_module("msvcrt") + locking: Callable[[int, int, int], None] = msvcrt.locking + locking(handle.fileno(), msvcrt.LK_NBLCK, 1) else: import fcntl