Patchwork D10206: typing: disable a few errors when accessing Windows specific attributes

login
register
mail settings
Submitter phabricator
Date March 13, 2021, 7:33 p.m.
Message ID <differential-rev-PHID-DREV-kgcibsbaz3qmnvgpnvfa-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48520/
State Superseded
Headers show

Comments

phabricator - March 13, 2021, 7:33 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is already guarded with conditionals.  The entire win32 module is
  conditionally loaded.
  
    File "/mnt/c/Users/Matt/hg/mercurial/utils/procutil.py", line 162, in <module>: No attribute 'winstdout' on module 'mercurial.posix' [module-attr]
    File "/mnt/c/Users/Matt/hg/mercurial/utils/procutil.py", line 163, in <module>: No attribute 'winstdout' on module 'mercurial.posix' [module-attr]
    File "/mnt/c/Users/Matt/hg/mercurial/utils/procutil.py", line 174, in <module>: No attribute 'winstdout' on module 'mercurial.posix' [module-attr]
    File "/mnt/c/Users/Matt/hg/mercurial/utils/procutil.py", line 175, in <module>: No attribute 'winstdout' on module 'mercurial.posix' [module-attr]

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D10206

AFFECTED FILES
  mercurial/utils/procutil.py
  mercurial/win32.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/win32.py b/mercurial/win32.py
--- a/mercurial/win32.py
+++ b/mercurial/win32.py
@@ -20,10 +20,12 @@ 
     pycompat,
 )
 
+# pytype: disable=module-attr
 _kernel32 = ctypes.windll.kernel32
 _advapi32 = ctypes.windll.advapi32
 _user32 = ctypes.windll.user32
 _crypt32 = ctypes.windll.crypt32
+# pytype: enable=module-attr
 
 _BOOL = ctypes.c_long
 _WORD = ctypes.c_ushort
@@ -311,7 +313,9 @@ 
 _kernel32.GetCurrentProcessId.argtypes = []
 _kernel32.GetCurrentProcessId.restype = _DWORD
 
+# pytype: disable=module-attr
 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD)
+# pytype: enable=module-attr
 _kernel32.SetConsoleCtrlHandler.argtypes = [_SIGNAL_HANDLER, _BOOL]
 _kernel32.SetConsoleCtrlHandler.restype = _BOOL
 
@@ -336,7 +340,9 @@ 
 _user32.ShowWindow.argtypes = [_HANDLE, ctypes.c_int]
 _user32.ShowWindow.restype = _BOOL
 
+# pytype: disable=module-attr
 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM)
+# pytype: enable=module-attr
 _user32.EnumWindows.argtypes = [_WNDENUMPROC, _LPARAM]
 _user32.EnumWindows.restype = _BOOL
 
@@ -357,7 +363,7 @@ 
     code = _kernel32.GetLastError()
     if code > 0x7FFFFFFF:
         code -= 2 ** 32
-    err = ctypes.WinError(code=code)
+    err = ctypes.WinError(code=code)  # pytype: disable=module-attr
     raise OSError(
         err.errno, '%s: %s' % (encoding.strfromlocal(name), err.strerror)
     )
@@ -466,7 +472,7 @@ 
 
 
 def peekpipe(pipe):
-    handle = msvcrt.get_osfhandle(pipe.fileno())
+    handle = msvcrt.get_osfhandle(pipe.fileno())  # pytype: disable=module-attr
     avail = _DWORD()
 
     if not _kernel32.PeekNamedPipe(
@@ -475,7 +481,7 @@ 
         err = _kernel32.GetLastError()
         if err == _ERROR_BROKEN_PIPE:
             return 0
-        raise ctypes.WinError(err)
+        raise ctypes.WinError(err)  # pytype: disable=module-attr
 
     return avail.value
 
@@ -506,10 +512,12 @@ 
     size = 600
     buf = ctypes.create_string_buffer(size + 1)
     len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size)
+    # pytype: disable=module-attr
     if len == 0:
         raise ctypes.WinError()  # Note: WinError is a function
     elif len == size:
         raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER)
+    # pytype: enable=module-attr
     return buf.value
 
 
@@ -528,7 +536,8 @@ 
     buf = ctypes.create_string_buffer(size)
 
     if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size):
-        raise ctypes.WinError()  # Note: WinError is a function
+        # Note: WinError is a function
+        raise ctypes.WinError()  # pytype: disable=module-attr
 
     return buf.value
 
@@ -558,7 +567,8 @@ 
     if not _kernel32.GetVolumeInformationA(
         volume, None, 0, None, None, None, ctypes.byref(name), size
     ):
-        raise ctypes.WinError()  # Note: WinError is a function
+        # Note: WinError is a function
+        raise ctypes.WinError()  # pytype: disable=module-attr
 
     return name.value
 
@@ -568,7 +578,7 @@ 
     size = _DWORD(300)
     buf = ctypes.create_string_buffer(size.value + 1)
     if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)):
-        raise ctypes.WinError()
+        raise ctypes.WinError()  # pytype: disable=module-attr
     return buf.value
 
 
@@ -589,7 +599,7 @@ 
     h = _SIGNAL_HANDLER(handler)
     _signalhandler.append(h)  # needed to prevent garbage collection
     if not _kernel32.SetConsoleCtrlHandler(h, True):
-        raise ctypes.WinError()
+        raise ctypes.WinError()  # pytype: disable=module-attr
 
 
 def hidewindow():
@@ -686,7 +696,7 @@ 
         ctypes.byref(pi),
     )
     if not res:
-        raise ctypes.WinError()
+        raise ctypes.WinError()  # pytype: disable=module-attr
 
     _kernel32.CloseHandle(pi.hProcess)
     _kernel32.CloseHandle(pi.hThread)
diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -152,8 +152,8 @@ 
 
     if pycompat.iswindows:
         # Work around Windows bugs.
-        stdout = platform.winstdout(stdout)
-        stderr = platform.winstdout(stderr)
+        stdout = platform.winstdout(stdout)  # pytype: disable=module-attr
+        stderr = platform.winstdout(stderr)  # pytype: disable=module-attr
     if isatty(stdout):
         # The standard library doesn't offer line-buffered binary streams.
         stdout = make_line_buffered(stdout)
@@ -164,8 +164,8 @@ 
     stderr = sys.stderr
     if pycompat.iswindows:
         # Work around Windows bugs.
-        stdout = platform.winstdout(stdout)
-        stderr = platform.winstdout(stderr)
+        stdout = platform.winstdout(stdout)  # pytype: disable=module-attr
+        stderr = platform.winstdout(stderr)  # pytype: disable=module-attr
     if isatty(stdout):
         if pycompat.iswindows:
             # The Windows C runtime library doesn't support line buffering.