fixed mypy issues

This commit is contained in:
Tim Riddermann 2023-07-18 17:37:29 +02:00
parent e39fc5b19d
commit 825783db57
3 changed files with 12 additions and 12 deletions

View file

@ -102,10 +102,10 @@ def csfield(
# Set default values in case of special sucons
if isinstance(orig_subcon, cs.Const):
const_subcon: "cs.Const[t.Any, t.Any, t.Any, t.Any]" = orig_subcon
const_subcon: "cs.Const[t.Any, t.Any]" = orig_subcon
default = const_subcon.value
elif isinstance(orig_subcon, cs.Default):
default_subcon: "cs.Default[t.Any, t.Any, t.Any, t.Any]" = orig_subcon
default_subcon: "cs.Default[t.Any, t.Any]" = orig_subcon
if callable(default_subcon.value):
default = None # context lambda is only defined at parsing/building
else:

View file

@ -22,13 +22,13 @@ IdentType = t.TypeVar("IdentType")
class ZeroIO(io.BufferedIOBase):
def read(self, __size: t.Optional[int] = None):
def read(self, __size: t.Optional[int] = None) -> bytes:
if __size is not None:
return bytes(__size)
else:
return bytes(0)
def read1(self, __size: int = 0):
def read1(self, __size: int = 0) -> bytes:
return bytes(__size)
@ -176,8 +176,8 @@ def common(
size = format.sizeof(**kw)
assert size == sizesample
else:
size = raises(format.sizeof, **kw)
assert size == sizesample
size_ex = raises(format.sizeof, **kw)
assert size_ex == sizesample
def setattrs(obj: T, **kwargs: t.Any) -> T:
@ -187,24 +187,24 @@ def setattrs(obj: T, **kwargs: t.Any) -> T:
return obj
def commonhex(format: "Construct[t.Any, t.Any]", hexdata: str):
def commonhex(format: "Construct[t.Any, t.Any]", hexdata: str) -> None:
commonbytes(format, binascii.unhexlify(hexdata))
def commondumpdeprecated(format: "Construct[t.Any, t.Any]", filename: str):
def commondumpdeprecated(format: "Construct[t.Any, t.Any]", filename: str) -> None:
filename = "tests/deprecated_gallery/blobs/" + filename
with open(filename, "rb") as f:
data = f.read()
commonbytes(format, data)
def commondump(format: "Construct[t.Any, t.Any]", filename: str):
def commondump(format: "Construct[t.Any, t.Any]", filename: str) -> None:
filename = "tests/gallery/blobs/" + filename
with open(filename, "rb") as f:
data = f.read()
commonbytes(format, data)
def commonbytes(format: "Construct[t.Any, t.Any]", data: bytes):
def commonbytes(format: "Construct[t.Any, t.Any]", data: bytes) -> None:
obj = format.parse(data)
format.build(obj)

View file

@ -712,8 +712,8 @@ def test_hexdump_regression_issue_188() -> None:
assert d.parse(b"MZ") == Container()
assert d.build(dict()) == b"MZ"
a = HexDump(Const(b"MZ"))
d = Struct(a)
b = HexDump(Const(b"MZ"))
d = Struct(b)
assert d.parse(b"MZ") == Container()
assert d.build(dict()) == b"MZ"