From 5037a3cc61ef65e1846805de3b4f6055e59d3b45 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 23 Feb 2019 19:50:47 +0100 Subject: add type hints to common.py --- common.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'common.py') diff --git a/common.py b/common.py index 552b10a..ef146c0 100644 --- a/common.py +++ b/common.py @@ -1,4 +1,8 @@ -def yield_lines(iterable): +import typing + +ByteIterable = typing.Iterable[bytes] + +def yield_lines(iterable: ByteIterable) -> ByteIterable: """Converts an arbitrary bytes iterable into an iterable that yields whole lines. The final byte of each returned value (except possibly the last one) is a newline or carriage return character. The concatenation of the input @@ -12,7 +16,7 @@ def yield_lines(iterable): if buff: yield buff -def decompress_stream(iterable, decompressor): +def decompress_stream(iterable: ByteIterable, decompressor) -> ByteIterable: """Decompress an iterable of bytes using the given decompressor into another (decompressed) iterable of bytes. The decompressor can be a bz2.BZ2Decompressor or lzma.LZMADecompressor instance.""" @@ -22,7 +26,7 @@ def decompress_stream(iterable, decompressor): if hasattr(decompressor, "flush"): yield decompressor.flush() -def yield_chunks(filelike, chunksize=65536): +def yield_chunks(filelike, chunksize=65536) -> ByteIterable: """Read the given file in chunks of the given size. Returns an itrable of contents. If the file is binary, it yields bytes, otherwise str.""" while True: -- cgit v1.2.3