typing: add type hints to mpatch implementations
authorMatt Harbison <matt_harbison@yahoo.com>
Tue, 08 Nov 2022 14:17:56 -0500
changeset 49599 94a797032fc4
parent 49598 594fc56c0af7
child 49600 b6fc602e074a
typing: add type hints to mpatch implementations Again, using `merge-pyi` to apply the stubs in cext and then manually type the private methods. The generated stub without these hints inferred very little, and the stuff it did was wrong.
mercurial/cffi/mpatch.py
mercurial/pure/mpatch.py
--- a/mercurial/cffi/mpatch.py	Tue Nov 08 13:59:16 2022 -0500
+++ b/mercurial/cffi/mpatch.py	Tue Nov 08 14:17:56 2022 -0500
@@ -6,6 +6,8 @@
 # GNU General Public License version 2 or any later version.
 
 
+from typing import List
+
 from ..pure.mpatch import *
 from ..pure.mpatch import mpatchError  # silence pyflakes
 from . import _mpatch  # pytype: disable=import-error
@@ -26,7 +28,7 @@
     return container[0]
 
 
-def patches(text, bins):
+def patches(text: bytes, bins: List[bytes]) -> bytes:
     lgt = len(bins)
     all = []
     if not lgt:
--- a/mercurial/pure/mpatch.py	Tue Nov 08 13:59:16 2022 -0500
+++ b/mercurial/pure/mpatch.py	Tue Nov 08 14:17:56 2022 -0500
@@ -9,6 +9,11 @@
 import io
 import struct
 
+from typing import (
+    List,
+    Tuple,
+)
+
 
 stringio = io.BytesIO
 
@@ -28,7 +33,9 @@
 # temporary string buffers.
 
 
-def _pull(dst, src, l):  # pull l bytes from src
+def _pull(
+    dst: List[Tuple[int, int]], src: List[Tuple[int, int]], l: int
+) -> None:  # pull l bytes from src
     while l:
         f = src.pop()
         if f[0] > l:  # do we need to split?
@@ -39,7 +46,7 @@
         l -= f[0]
 
 
-def _move(m, dest, src, count):
+def _move(m: stringio, dest: int, src: int, count: int) -> None:
     """move count bytes from src to dest
 
     The file pointer is left at the end of dest.
@@ -50,7 +57,9 @@
     m.write(buf)
 
 
-def _collect(m, buf, list):
+def _collect(
+    m: stringio, buf: int, list: List[Tuple[int, int]]
+) -> Tuple[int, int]:
     start = buf
     for l, p in reversed(list):
         _move(m, buf, p, l)
@@ -58,7 +67,7 @@
     return (buf - start, start)
 
 
-def patches(a, bins):
+def patches(a: bytes, bins: List[bytes]) -> bytes:
     if not bins:
         return a
 
@@ -111,7 +120,7 @@
     return m.read(t[0])
 
 
-def patchedsize(orig, delta):
+def patchedsize(orig: int, delta: bytes) -> int:
     outlen, last, bin = 0, 0, 0
     binend = len(delta)
     data = 12