changeset 51994:d7f17819ae9e

interfaces: introduce and use a protocol class for the `mpatch` module See f2832de2a46c for details when this was done for the `bdiff` module. Two things worth pointing out- 1) The `cffi` module "inherits" the `pure` implementation of `patchedsize()` because of its wildcard import. 2) It's odd that the `mpatchError` lives in both `pure` and `cext` modules. I initially thought to move the exception into the new class, and make the existing class name an alias to the class in the new location, but the exception is created in C code by the `cext` module, so that won't work. I don't think a protocol class is approriate, because there's nothing special about the class to distinguish from any other `Exception`. Fortunately, nobody is catching this exception in core, so we can kick the can down the road.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 05 Oct 2024 18:58:20 -0400
parents 5e2f0fec0a47
children 145f66ea1664
files mercurial/interfaces/modules.py mercurial/mdiff.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/interfaces/modules.py	Tue Oct 08 21:46:22 2024 +0200
+++ b/mercurial/interfaces/modules.py	Sat Oct 05 18:58:20 2024 -0400
@@ -73,3 +73,13 @@
 
         Raises ValueError if non-ASCII characters have to be escaped.
         """
+
+
+class MPatch(Protocol):
+    """A protocol class for the various mpatch module implementations."""
+
+    def patches(self, a: bytes, bins: List[bytes]) -> bytes:
+        ...
+
+    def patchedsize(self, orig: int, delta: bytes) -> int:
+        ...
--- a/mercurial/mdiff.py	Tue Oct 08 21:46:22 2024 +0200
+++ b/mercurial/mdiff.py	Sat Oct 05 18:58:20 2024 -0400
@@ -39,7 +39,7 @@
 from .utils import dateutil
 
 bdiff: intmod.BDiff = policy.importmod('bdiff')
-mpatch = policy.importmod('mpatch')
+mpatch: intmod.MPatch = policy.importmod('mpatch')
 
 blocks = bdiff.blocks
 fixws = bdiff.fixws