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 @@ ...@@ -6,6 +6,8 @@
# GNU General Public License version 2 or any later version. # GNU General Public License version 2 or any later version.
from typing import List
from ..pure.mpatch import * from ..pure.mpatch import *
from ..pure.mpatch import mpatchError # silence pyflakes from ..pure.mpatch import mpatchError # silence pyflakes
from . import _mpatch # pytype: disable=import-error from . import _mpatch # pytype: disable=import-error
...@@ -26,7 +28,7 @@ ...@@ -26,7 +28,7 @@
return container[0] return container[0]
def patches(text, bins): def patches(text: bytes, bins: List[bytes]) -> bytes:
lgt = len(bins) lgt = len(bins)
all = [] all = []
if not lgt: if not lgt:
......
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
import io import io
import struct import struct
from typing import (
List,
Tuple,
)
stringio = io.BytesIO stringio = io.BytesIO
...@@ -28,7 +33,9 @@ ...@@ -28,7 +33,9 @@
# temporary string buffers. # 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: while l:
f = src.pop() f = src.pop()
if f[0] > l: # do we need to split? if f[0] > l: # do we need to split?
...@@ -39,7 +46,7 @@ ...@@ -39,7 +46,7 @@
l -= f[0] 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 """move count bytes from src to dest
The file pointer is left at the end of dest. The file pointer is left at the end of dest.
...@@ -50,7 +57,9 @@ ...@@ -50,7 +57,9 @@
m.write(buf) m.write(buf)
def _collect(m, buf, list): def _collect(
m: stringio, buf: int, list: List[Tuple[int, int]]
) -> Tuple[int, int]:
start = buf start = buf
for l, p in reversed(list): for l, p in reversed(list):
_move(m, buf, p, l) _move(m, buf, p, l)
...@@ -58,7 +67,7 @@ ...@@ -58,7 +67,7 @@
return (buf - start, start) return (buf - start, start)
def patches(a, bins): def patches(a: bytes, bins: List[bytes]) -> bytes:
if not bins: if not bins:
return a return a
...@@ -111,7 +120,7 @@ ...@@ -111,7 +120,7 @@
return m.read(t[0]) return m.read(t[0])
def patchedsize(orig, delta): def patchedsize(orig: int, delta: bytes) -> int:
outlen, last, bin = 0, 0, 0 outlen, last, bin = 0, 0, 0
binend = len(delta) binend = len(delta)
data = 12 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