changeset 48284:9de0823705b4

typing: add more type hints to the errors module 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. Differential Revision: https://phab.mercurial-scm.org/D11719
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 23 Oct 2021 17:13:57 -0400
parents ebac18733142
children 4216f5561c3b
files mercurial/error.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/error.py	Sat Oct 23 16:04:05 2021 -0400
+++ b/mercurial/error.py	Sat Oct 23 17:13:57 2021 -0400
@@ -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: