Skip to content
Snippets Groups Projects
Commit 94a797032fc4 authored by Matt Harbison's avatar Matt Harbison
Browse files

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.
parent 594fc56c0af7
No related branches found
No related tags found
2 merge requests!485branching: merge default into stable,!295typing: small fixes to cext and pure
......@@ -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:
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment