Patchwork D11719: typing: add more type hints to the errors module

login
register
mail settings
Submitter phabricator
Date Oct. 23, 2021, 10:41 p.m.
Message ID <differential-rev-PHID-DREV-ddw5zxvdmfz7ggnxkgcz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50044/
State Superseded
Headers show

Comments

phabricator - Oct. 23, 2021, 10:41 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  These were found by looking for `Any` types in the generated `*.pyi` file after
  running the tests.  There are some more complicated types that I'm not sure of,
  and am leaving untyped.  I also can't figure out how to get `self.hint` to be
  anything other than `Any` in most classes.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/error.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -31,6 +31,7 @@ 
 
 
 def _tobytes(exc):
+    # type: (...) -> bytes
     """Byte-stringify exception in the same way as BaseException_str()"""
     if not exc.args:
         return b''
@@ -47,7 +48,7 @@ 
     """
 
     def __init__(self, *args, **kw):
-        self.hint = kw.pop('hint', None)
+        self.hint = kw.pop('hint', None)  # type: Optional[bytes]
         super(Hint, self).__init__(*args, **kw)
 
 
@@ -71,6 +72,7 @@ 
     if pycompat.ispy3:
 
         def __str__(self):
+            # type: () -> str
             # the output would be unreadable if the message was translated,
             # but do not replace it with encoding.strfromlocal(), which
             # may raise another exception.
@@ -105,6 +107,7 @@ 
 
 class SidedataHashError(RevlogError):
     def __init__(self, key, expected, got):
+        # type: (int, bytes, bytes) -> None
         self.hint = None
         self.sidedatakey = key
         self.expecteddigest = expected
@@ -117,6 +120,7 @@ 
 
 class LookupError(RevlogError, KeyError):
     def __init__(self, name, index, message):
+        # type: (bytes, bytes, bytes) -> None
         self.name = name
         self.index = index
         # this can't be called 'message' because at least some installs of
@@ -343,6 +347,7 @@ 
     """Exception raised when a remote repo reports failure"""
 
     def __init__(self, message=None, hint=None):
+        # type: (Optional[bytes], Optional[bytes]) -> None
         from .i18n import _
 
         if message: