diff options
author | Helmut Grohne <helmut@subdivi.de> | 2019-02-23 19:50:47 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2019-02-23 19:50:47 +0100 |
commit | 5037a3cc61ef65e1846805de3b4f6055e59d3b45 (patch) | |
tree | a54c3028b46c641aff30ecf6aee3db16f6c0f8d7 | |
parent | b3387fc348d732aea61235072c3f8251a3255e56 (diff) | |
download | crossqa-5037a3cc61ef65e1846805de3b4f6055e59d3b45.tar.gz |
add type hints to common.py
-rw-r--r-- | common.py | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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: |