typing: add a few type hints to `mercurial/revlog.py`
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 10 Jul 2024 18:19:32 -0400
changeset 51677 df6ce326936f
parent 51676 031d66801d5f
child 51678 0e16efe30866
typing: add a few type hints to `mercurial/revlog.py` Somewhere between hg 3dbc7b1ecaba and hg 8e3f6b5bf720, pytype stopped being able to infer the type for `_docket_file` and `compress()`. Lock those types in before they get lost.
mercurial/revlog.py
--- a/mercurial/revlog.py	Wed Jul 10 18:05:40 2024 -0400
+++ b/mercurial/revlog.py	Wed Jul 10 18:19:32 2024 -0400
@@ -23,6 +23,11 @@
 import weakref
 import zlib
 
+from typing import (
+    Optional,
+    Tuple,
+)
+
 # import stuff from node for others to import from revlog
 from .node import (
     bin,
@@ -558,7 +563,7 @@
         c = self._get_decompressor(t)
         return c.decompress
 
-    def _get_decompressor(self, t):
+    def _get_decompressor(self, t: bytes):
         try:
             compressor = self._decompressors[t]
         except KeyError:
@@ -574,7 +579,7 @@
                 )
         return compressor
 
-    def compress(self, data):
+    def compress(self, data: bytes) -> Tuple[bytes, bytes]:
         """Generate a possibly-compressed representation of data."""
         if not data:
             return b'', data
@@ -589,7 +594,7 @@
             return b'', data
         return b'u', data
 
-    def decompress(self, data):
+    def decompress(self, data: bytes):
         """Decompress a revlog chunk.
 
         The chunk is expected to begin with a header identifying the
@@ -1296,6 +1301,8 @@
         features = FEATURES_BY_VERSION[_format_version]
         return features[b'inline'](_format_flags)
 
+    _docket_file: Optional[bytes]
+
     def __init__(
         self,
         opener,
@@ -3081,7 +3088,7 @@
                 sidedata=sidedata,
             )
 
-    def compress(self, data):
+    def compress(self, data: bytes) -> Tuple[bytes, bytes]:
         return self._inner.compress(data)
 
     def decompress(self, data):