D10208: typing: disable module attribute warnings for properly conditionalized code

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Sat Mar 13 19:34:15 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  mercurial/dispatch.py
  mercurial/pure/osutil.py
  mercurial/sslutil.py

CHANGE DETAILS

diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
--- a/mercurial/sslutil.py
+++ b/mercurial/sslutil.py
@@ -543,7 +543,9 @@
     # Use the list of more secure ciphers if found in the ssl module.
     if util.safehasattr(ssl, b'_RESTRICTED_SERVER_CIPHERS'):
         sslcontext.options |= getattr(ssl, 'OP_CIPHER_SERVER_PREFERENCE', 0)
+        # pytype: disable=module-attr
         sslcontext.set_ciphers(ssl._RESTRICTED_SERVER_CIPHERS)
+        # pytype: enable=module-attr
 
     if requireclientcert:
         sslcontext.verify_mode = ssl.CERT_REQUIRED
diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -172,7 +172,7 @@
 else:
     import msvcrt
 
-    _kernel32 = ctypes.windll.kernel32
+    _kernel32 = ctypes.windll.kernel32  # pytype: disable=module-attr
 
     _DWORD = ctypes.c_ulong
     _LPCSTR = _LPSTR = ctypes.c_char_p
@@ -216,7 +216,7 @@
     _kernel32.CreateFileA.restype = _HANDLE
 
     def _raiseioerror(name):
-        err = ctypes.WinError()
+        err = ctypes.WinError()  # pytype: disable=module-attr
         raise IOError(
             err.errno, '%s: %s' % (encoding.strfromlocal(name), err.strerror)
         )
@@ -271,7 +271,7 @@
             if fh == _INVALID_HANDLE_VALUE:
                 _raiseioerror(name)
 
-            fd = msvcrt.open_osfhandle(fh, flags)
+            fd = msvcrt.open_osfhandle(fh, flags)  # pytype: disable=module-attr
             if fd == -1:
                 _kernel32.CloseHandle(fh)
                 _raiseioerror(name)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -173,7 +173,9 @@
                 "line_buffering": sys.stdout.line_buffering,
             }
             if util.safehasattr(sys.stdout, "write_through"):
+                # pytype: disable=attribute-error
                 kwargs["write_through"] = sys.stdout.write_through
+                # pytype: enable=attribute-error
             sys.stdout = io.TextIOWrapper(
                 sys.stdout.buffer,
                 sys.stdout.encoding,
@@ -187,7 +189,9 @@
                 "line_buffering": sys.stderr.line_buffering,
             }
             if util.safehasattr(sys.stderr, "write_through"):
+                # pytype: disable=attribute-error
                 kwargs["write_through"] = sys.stderr.write_through
+                # pytype: enable=attribute-error
             sys.stderr = io.TextIOWrapper(
                 sys.stderr.buffer,
                 sys.stderr.encoding,



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


More information about the Mercurial-devel mailing list