Fix miscellaneous mypy errors

This commit is contained in:
dgelessus 2019-12-30 01:42:38 +01:00
parent 1a416defed
commit 4e1cd05412
2 changed files with 6 additions and 4 deletions

View File

@ -420,7 +420,7 @@ def add_resource_filter_args(ap: argparse.ArgumentParser) -> None:
ap.add_argument("filter", nargs="*", help="One or more filters to select resources. If no filters are specified, all resources are selected.") ap.add_argument("filter", nargs="*", help="One or more filters to select resources. If no filters are specified, all resources are selected.")
def open_resource_file(file: str, *, fork: str = None) -> api.ResourceFile: def open_resource_file(file: str, *, fork: str) -> api.ResourceFile:
"""Open a resource file at the given path, using the specified fork.""" """Open a resource file at the given path, using the specified fork."""
if file == "-": if file == "-":
@ -467,8 +467,8 @@ on Mac OS X normally have both parts of the header data set to all zero bytes.
if ns.format == "dump": if ns.format == "dump":
dump_func = hexdump dump_func = hexdump
elif ns.format == "dump-text": elif ns.format == "dump-text":
def dump_func(d): def dump_func(data: bytes) -> None:
print(translate_text(d)) print(translate_text(data))
else: else:
raise AssertionError(f"Unhandled --format: {ns.format!r}") raise AssertionError(f"Unhandled --format: {ns.format!r}")
@ -619,6 +619,7 @@ Display technical information about one or more resources.
except compress.DecompressError: except compress.DecompressError:
print("\t\t(failed to parse compressed resource header)") print("\t\t(failed to parse compressed resource header)")
else: else:
assert res.compressed_info is not None
for line in format_compressed_header_info(res.compressed_info): for line in format_compressed_header_info(res.compressed_info):
print(f"\t\t{line}") print(f"\t\t{line}")

View File

@ -165,7 +165,8 @@ def make_peekable(stream: typing.BinaryIO) -> "PeekableIO":
if hasattr(stream, "peek"): if hasattr(stream, "peek"):
# Stream is already peekable, nothing to be done. # Stream is already peekable, nothing to be done.
return typing.cast("PeekableIO", stream) return typing.cast("PeekableIO", stream)
elif isinstance(stream, io.RawIOBase): elif not typing.TYPE_CHECKING and isinstance(stream, io.RawIOBase):
# This branch is skipped when type checking - mypy incorrectly warns about this code being unreachable, because it thinks that a typing.BinaryIO cannot be an instance of io.RawIOBase.
# Raw IO streams can be wrapped efficiently using BufferedReader. # Raw IO streams can be wrapped efficiently using BufferedReader.
return io.BufferedReader(stream) return io.BufferedReader(stream)
else: else: