diff mercurial/scmwindows.py @ 49808:7a4143428db7

typing: add type hints to the platform specific scm modules Surprisingly, pytype struggled to figure out the return types in the posix functions.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 15 Dec 2022 15:41:59 -0500
parents d500df2e8034
children 7a80a614c9e5
line wrap: on
line diff
--- a/mercurial/scmwindows.py	Thu Dec 15 01:05:27 2022 -0500
+++ b/mercurial/scmwindows.py	Thu Dec 15 15:41:59 2022 -0500
@@ -1,5 +1,10 @@
 import os
 
+from typing import (
+    List,
+    Tuple,
+)
+
 from . import (
     encoding,
     pycompat,
@@ -7,6 +12,9 @@
     win32,
 )
 
+if pycompat.TYPE_CHECKING:
+    from . import ui as uimod
+
 try:
     import _winreg as winreg  # pytype: disable=import-error
 
@@ -19,7 +27,7 @@
 fallbackpager = b'more'
 
 
-def systemrcpath():
+def systemrcpath() -> List[bytes]:
     '''return default os-specific hgrc search path'''
     rcpath = []
     filename = win32.executablepath()
@@ -27,7 +35,7 @@
     progrc = os.path.join(os.path.dirname(filename), b'mercurial.ini')
     rcpath.append(progrc)
 
-    def _processdir(progrcd):
+    def _processdir(progrcd: bytes) -> None:
         if os.path.isdir(progrcd):
             for f, kind in sorted(util.listdir(progrcd)):
                 if f.endswith(b'.rc'):
@@ -68,7 +76,7 @@
     return rcpath
 
 
-def userrcpath():
+def userrcpath() -> List[bytes]:
     '''return os-specific hgrc search path to the user dir'''
     home = _legacy_expanduser(b'~')
     path = [os.path.join(home, b'mercurial.ini'), os.path.join(home, b'.hgrc')]
@@ -79,7 +87,7 @@
     return path
 
 
-def _legacy_expanduser(path):
+def _legacy_expanduser(path: bytes) -> bytes:
     """Expand ~ and ~user constructs in the pre 3.8 style"""
 
     # Python 3.8+ changed the expansion of '~' from HOME to USERPROFILE.  See
@@ -111,5 +119,5 @@
     return userhome + path[i:]
 
 
-def termsize(ui):
+def termsize(ui: "uimod.ui") -> Tuple[int, int]:
     return win32.termsize()