refactor: read msvcrt as the runtime holds it

This commit is contained in:
Abdessamad Derraz committed 2026-11-17 13:51:58 +01:00
1 parent 056c81e9a3
commit 0cfe8cd5c9
1 file changed
+6 -2
+6 -2
View File
@@ -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