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

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Sat Oct 23 22:41:13 UTC 2021


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

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:



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


More information about the Mercurial-devel mailing list