Patchwork D7510: windows: suppress pytype warnings for Windows imports and functions

login
register
mail settings
Submitter phabricator
Date Nov. 23, 2019, 5:15 a.m.
Message ID <differential-rev-PHID-DREV-xbq4w5ano4h5cdgo5sjy-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43463/
State Superseded
Headers show

Comments

phabricator - Nov. 23, 2019, 5:15 a.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This should allow the modules to not be excluded, and not generate complaints on
  non Windows platforms.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/pycompat.py
  mercurial/scmwindows.py
  mercurial/windows.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 23, 2019, 5:17 a.m.
mharbison72 added a comment.


  I'm not sure if there are plans to vendor *.pyi files.  Maybe that could be used to backfill platform specific modules instead of doing this.  But for now is seems better to get the error count and blacklist length reduced.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7510/new/

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

To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 24, 2019, 12:58 a.m.
indygreg added a comment.


  In D7510#110343 <https://phab.mercurial-scm.org/D7510#110343>, @mharbison72 wrote:
  
  > I'm not sure if there are plans to vendor *.pyi files.  Maybe that could be used to backfill platform specific modules instead of doing this.  But for now is seems better to get the error count and blacklist length reduced.
  
  I think `.pyi` files are a bit annoying. And since Python 2 support isn't long for this world, I think we should hold out and just switch to inline type annotations as soon as we drop Python 2 support. This assumes we make good on our plan to drop Python 2 after the first release in 2020 at latest. If not, we should consider vendoring `.pyi` files so we can have nicer things sooner.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7510/new/

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

To: mharbison72, #hg-reviewers, dlax
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -26,11 +26,12 @@ 
 )
 
 try:
-    import _winreg as winreg
+    import _winreg as winreg  # pytype: disable=import-error
 
     winreg.CloseKey
 except ImportError:
-    import winreg
+    # py2 only
+    import winreg  # pytype: disable=import-error
 
 osutil = policy.importmod('osutil')
 
@@ -282,7 +283,7 @@ 
     # fileno(), usually set to -1.
     fno = getattr(fd, 'fileno', None)
     if fno is not None and fno() >= 0:
-        msvcrt.setmode(fno(), os.O_BINARY)
+        msvcrt.setmode(fno(), os.O_BINARY)  # pytype: disable=module-attr
 
 
 def pconvert(path):
diff --git a/mercurial/scmwindows.py b/mercurial/scmwindows.py
--- a/mercurial/scmwindows.py
+++ b/mercurial/scmwindows.py
@@ -10,11 +10,12 @@ 
 )
 
 try:
-    import _winreg as winreg
+    import _winreg as winreg  # pytype: disable=import-error
 
     winreg.CloseKey
 except ImportError:
-    import winreg
+    # py2 only
+    import winreg  # pytype: disable=import-error
 
 # MS-DOS 'more' is the only pager available by default on Windows.
 fallbackpager = b'more'
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -99,7 +99,7 @@ 
         # Otherwise non-ASCII filenames in existing repositories would be
         # corrupted.
         # This must be set once prior to any fsencode/fsdecode calls.
-        sys._enablelegacywindowsfsencoding()
+        sys._enablelegacywindowsfsencoding()  # pytype: disable=module-attr
 
     fsencode = os.fsencode
     fsdecode = os.fsdecode