11import contextlib
22import errno
3+ import os
34
45
5- try : # pragma: no cover (windows)
6+ if os . name == 'nt' : # pragma: no cover (windows)
67 import msvcrt
78
89 # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/locking
1415 @contextlib .contextmanager
1516 def _locked (fileno , blocked_cb ):
1617 try :
17- msvcrt .locking (fileno , msvcrt .LK_NBLCK , _region )
18+ # TODO: https://github.com/python/typeshed/pull/3607
19+ msvcrt .locking (fileno , msvcrt .LK_NBLCK , _region ) # type: ignore
1820 except OSError :
1921 blocked_cb ()
2022 while True :
2123 try :
22- msvcrt .locking (fileno , msvcrt .LK_LOCK , _region )
24+ # TODO: https://github.com/python/typeshed/pull/3607
25+ msvcrt .locking (fileno , msvcrt .LK_LOCK , _region ) # type: ignore # noqa: E501
2326 except OSError as e :
2427 # Locking violation. Returned when the _LK_LOCK or _LK_RLCK
2528 # flag is specified and the file cannot be locked after 10
@@ -37,8 +40,9 @@ def _locked(fileno, blocked_cb):
3740 # The documentation however states:
3841 # "Regions should be locked only briefly and should be unlocked
3942 # before closing a file or exiting the program."
40- msvcrt .locking (fileno , msvcrt .LK_UNLCK , _region )
41- except ImportError : # pragma: windows no cover
43+ # TODO: https://github.com/python/typeshed/pull/3607
44+ msvcrt .locking (fileno , msvcrt .LK_UNLCK , _region ) # type: ignore
45+ else : # pramga: windows no cover
4246 import fcntl
4347
4448 @contextlib .contextmanager
0 commit comments