##// END OF EJS Templates
typing: disable a few errors when accessing Windows specific attributes...
Matt Harbison -
r47542:65f437c2 stable
parent child Browse files
Show More
@@ -152,8 +152,8 b' if pycompat.ispy3:'
152
152
153 if pycompat.iswindows:
153 if pycompat.iswindows:
154 # Work around Windows bugs.
154 # Work around Windows bugs.
155 stdout = platform.winstdout(stdout)
155 stdout = platform.winstdout(stdout) # pytype: disable=module-attr
156 stderr = platform.winstdout(stderr)
156 stderr = platform.winstdout(stderr) # pytype: disable=module-attr
157 if isatty(stdout):
157 if isatty(stdout):
158 # The standard library doesn't offer line-buffered binary streams.
158 # The standard library doesn't offer line-buffered binary streams.
159 stdout = make_line_buffered(stdout)
159 stdout = make_line_buffered(stdout)
@@ -164,8 +164,8 b' else:'
164 stderr = sys.stderr
164 stderr = sys.stderr
165 if pycompat.iswindows:
165 if pycompat.iswindows:
166 # Work around Windows bugs.
166 # Work around Windows bugs.
167 stdout = platform.winstdout(stdout)
167 stdout = platform.winstdout(stdout) # pytype: disable=module-attr
168 stderr = platform.winstdout(stderr)
168 stderr = platform.winstdout(stderr) # pytype: disable=module-attr
169 if isatty(stdout):
169 if isatty(stdout):
170 if pycompat.iswindows:
170 if pycompat.iswindows:
171 # The Windows C runtime library doesn't support line buffering.
171 # The Windows C runtime library doesn't support line buffering.
@@ -20,10 +20,12 b' from . import ('
20 pycompat,
20 pycompat,
21 )
21 )
22
22
23 # pytype: disable=module-attr
23 _kernel32 = ctypes.windll.kernel32
24 _kernel32 = ctypes.windll.kernel32
24 _advapi32 = ctypes.windll.advapi32
25 _advapi32 = ctypes.windll.advapi32
25 _user32 = ctypes.windll.user32
26 _user32 = ctypes.windll.user32
26 _crypt32 = ctypes.windll.crypt32
27 _crypt32 = ctypes.windll.crypt32
28 # pytype: enable=module-attr
27
29
28 _BOOL = ctypes.c_long
30 _BOOL = ctypes.c_long
29 _WORD = ctypes.c_ushort
31 _WORD = ctypes.c_ushort
@@ -311,7 +313,9 b' except AttributeError:'
311 _kernel32.GetCurrentProcessId.argtypes = []
313 _kernel32.GetCurrentProcessId.argtypes = []
312 _kernel32.GetCurrentProcessId.restype = _DWORD
314 _kernel32.GetCurrentProcessId.restype = _DWORD
313
315
316 # pytype: disable=module-attr
314 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD)
317 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD)
318 # pytype: enable=module-attr
315 _kernel32.SetConsoleCtrlHandler.argtypes = [_SIGNAL_HANDLER, _BOOL]
319 _kernel32.SetConsoleCtrlHandler.argtypes = [_SIGNAL_HANDLER, _BOOL]
316 _kernel32.SetConsoleCtrlHandler.restype = _BOOL
320 _kernel32.SetConsoleCtrlHandler.restype = _BOOL
317
321
@@ -336,7 +340,9 b' except AttributeError:'
336 _user32.ShowWindow.argtypes = [_HANDLE, ctypes.c_int]
340 _user32.ShowWindow.argtypes = [_HANDLE, ctypes.c_int]
337 _user32.ShowWindow.restype = _BOOL
341 _user32.ShowWindow.restype = _BOOL
338
342
343 # pytype: disable=module-attr
339 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM)
344 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM)
345 # pytype: enable=module-attr
340 _user32.EnumWindows.argtypes = [_WNDENUMPROC, _LPARAM]
346 _user32.EnumWindows.argtypes = [_WNDENUMPROC, _LPARAM]
341 _user32.EnumWindows.restype = _BOOL
347 _user32.EnumWindows.restype = _BOOL
342
348
@@ -357,7 +363,7 b' def _raiseoserror(name):'
357 code = _kernel32.GetLastError()
363 code = _kernel32.GetLastError()
358 if code > 0x7FFFFFFF:
364 if code > 0x7FFFFFFF:
359 code -= 2 ** 32
365 code -= 2 ** 32
360 err = ctypes.WinError(code=code)
366 err = ctypes.WinError(code=code) # pytype: disable=module-attr
361 raise OSError(
367 raise OSError(
362 err.errno, '%s: %s' % (encoding.strfromlocal(name), err.strerror)
368 err.errno, '%s: %s' % (encoding.strfromlocal(name), err.strerror)
363 )
369 )
@@ -466,7 +472,7 b' def samedevice(path1, path2):'
466
472
467
473
468 def peekpipe(pipe):
474 def peekpipe(pipe):
469 handle = msvcrt.get_osfhandle(pipe.fileno())
475 handle = msvcrt.get_osfhandle(pipe.fileno()) # pytype: disable=module-attr
470 avail = _DWORD()
476 avail = _DWORD()
471
477
472 if not _kernel32.PeekNamedPipe(
478 if not _kernel32.PeekNamedPipe(
@@ -475,7 +481,7 b' def peekpipe(pipe):'
475 err = _kernel32.GetLastError()
481 err = _kernel32.GetLastError()
476 if err == _ERROR_BROKEN_PIPE:
482 if err == _ERROR_BROKEN_PIPE:
477 return 0
483 return 0
478 raise ctypes.WinError(err)
484 raise ctypes.WinError(err) # pytype: disable=module-attr
479
485
480 return avail.value
486 return avail.value
481
487
@@ -506,10 +512,12 b' def executablepath():'
506 size = 600
512 size = 600
507 buf = ctypes.create_string_buffer(size + 1)
513 buf = ctypes.create_string_buffer(size + 1)
508 len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size)
514 len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size)
515 # pytype: disable=module-attr
509 if len == 0:
516 if len == 0:
510 raise ctypes.WinError() # Note: WinError is a function
517 raise ctypes.WinError() # Note: WinError is a function
511 elif len == size:
518 elif len == size:
512 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER)
519 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER)
520 # pytype: enable=module-attr
513 return buf.value
521 return buf.value
514
522
515
523
@@ -528,7 +536,8 b' def getvolumename(path):'
528 buf = ctypes.create_string_buffer(size)
536 buf = ctypes.create_string_buffer(size)
529
537
530 if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size):
538 if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size):
531 raise ctypes.WinError() # Note: WinError is a function
539 # Note: WinError is a function
540 raise ctypes.WinError() # pytype: disable=module-attr
532
541
533 return buf.value
542 return buf.value
534
543
@@ -558,7 +567,8 b' def getfstype(path):'
558 if not _kernel32.GetVolumeInformationA(
567 if not _kernel32.GetVolumeInformationA(
559 volume, None, 0, None, None, None, ctypes.byref(name), size
568 volume, None, 0, None, None, None, ctypes.byref(name), size
560 ):
569 ):
561 raise ctypes.WinError() # Note: WinError is a function
570 # Note: WinError is a function
571 raise ctypes.WinError() # pytype: disable=module-attr
562
572
563 return name.value
573 return name.value
564
574
@@ -568,7 +578,7 b' def getuser():'
568 size = _DWORD(300)
578 size = _DWORD(300)
569 buf = ctypes.create_string_buffer(size.value + 1)
579 buf = ctypes.create_string_buffer(size.value + 1)
570 if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)):
580 if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)):
571 raise ctypes.WinError()
581 raise ctypes.WinError() # pytype: disable=module-attr
572 return buf.value
582 return buf.value
573
583
574
584
@@ -589,7 +599,7 b' def setsignalhandler():'
589 h = _SIGNAL_HANDLER(handler)
599 h = _SIGNAL_HANDLER(handler)
590 _signalhandler.append(h) # needed to prevent garbage collection
600 _signalhandler.append(h) # needed to prevent garbage collection
591 if not _kernel32.SetConsoleCtrlHandler(h, True):
601 if not _kernel32.SetConsoleCtrlHandler(h, True):
592 raise ctypes.WinError()
602 raise ctypes.WinError() # pytype: disable=module-attr
593
603
594
604
595 def hidewindow():
605 def hidewindow():
@@ -686,7 +696,7 b' def spawndetached(args):'
686 ctypes.byref(pi),
696 ctypes.byref(pi),
687 )
697 )
688 if not res:
698 if not res:
689 raise ctypes.WinError()
699 raise ctypes.WinError() # pytype: disable=module-attr
690
700
691 _kernel32.CloseHandle(pi.hProcess)
701 _kernel32.CloseHandle(pi.hProcess)
692 _kernel32.CloseHandle(pi.hThread)
702 _kernel32.CloseHandle(pi.hThread)
General Comments 0
You need to be logged in to leave comments. Login now