diff mercurial/interfaces/repository.py @ 52503:048c11993d6a

typing: (mostly) align the signatures of `imanifestrevisionstored` overrides When we change the implementations to subclass this explicitly, pytype complains that the signatures mismatch for various methods. It seems hung up on ones in `mercurial.manifest` that have type hints on the return value, but lacked it in the Protocol class (which it thinks returns `None` if there's no annotation). The tricky part is that a lot of the return types in the `mercurial.manifest` module are custom types specific to that module (e.g. `'manifestctx' | 'treemanifestctx'`). Those should probably be replaced with Protocol classes. I was going to avoid making a long series longer by disabling that check for now by putting `Any` as the return type on the Protocol class methods, and then realized the problem is the class isn't marked as a Protocol (that property isn't inherited). For now, lock in the synchronized signatures.
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 23 Oct 2024 12:44:09 -0400
parents a1dd484bf33b
children cdd4bc69bfc1
line wrap: on
line diff
--- a/mercurial/interfaces/repository.py	Tue Oct 22 22:28:10 2024 -0400
+++ b/mercurial/interfaces/repository.py	Wed Oct 23 12:44:09 2024 -0400
@@ -12,6 +12,7 @@
 
 from typing import (
     Any,
+    Collection,
     Protocol,
 )
 
@@ -1173,13 +1174,13 @@
 class imanifestrevisionstored(imanifestrevisionbase):
     """Interface representing a manifest revision committed to storage."""
 
-    def node(self):
+    def node(self) -> bytes:
         """The binary node for this manifest."""
 
     parents: list[bytes]
     """List of binary nodes that are parents for this manifest revision."""
 
-    def readdelta(self, shallow=False):
+    def readdelta(self, shallow: bool = False):
         """Obtain the manifest data structure representing changes from parent.
 
         This manifest is compared to its 1st parent. A new manifest
@@ -1194,7 +1195,12 @@
         The returned object conforms to the ``imanifestdict`` interface.
         """
 
-    def read_any_fast_delta(self, valid_bases=None, *, shallow=False):
+    def read_any_fast_delta(
+        self,
+        valid_bases: Collection[int] | None = None,
+        *,
+        shallow: bool = False,
+    ):
         """read some manifest information as fast if possible
 
         This might return a "delta", a manifest object containing only file
@@ -1217,7 +1223,7 @@
         The returned object conforms to the ``imanifestdict`` interface.
         """
 
-    def read_delta_parents(self, *, shallow=False, exact=True):
+    def read_delta_parents(self, *, shallow: bool = False, exact: bool = True):
         """return a diff from this revision against both parents.
 
         If `exact` is False, this might return a superset of the diff, containing
@@ -1231,7 +1237,7 @@
 
         The returned object conforms to the ``imanifestdict`` interface."""
 
-    def read_delta_new_entries(self, *, shallow=False):
+    def read_delta_new_entries(self, *, shallow: bool = False):
         """Return a manifest containing just the entries that might be new to
         the repository.
 
@@ -1246,13 +1252,13 @@
 
         The returned object conforms to the ``imanifestdict`` interface."""
 
-    def readfast(self, shallow=False):
+    def readfast(self, shallow: bool = False):
         """Calls either ``read()`` or ``readdelta()``.
 
         The faster of the two options is called.
         """
 
-    def find(self, key):
+    def find(self, key: bytes) -> tuple[bytes, bytes]:
         """Calls self.read().find(key)``.
 
         Returns a 2-tuple of ``(node, flags)`` or raises ``KeyError``.