Skip to content

Commit

Permalink
fixed mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Riddermann committed Jul 18, 2023
1 parent e39fc5b commit 825783d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions construct_typed/dataclass_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/declarativeunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@


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)


Expand Down Expand Up @@ -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:
Expand All @@ -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)
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 825783d

Please sign in to comment.