I'm parsing a stream from a zip file, and mypy shows the following error
Argument 1 to "parse_stream" of "Construct" has incompatible type "IO[bytes]"; expected "BinaryIO" [arg-type] (11:32)
I believe that parse_stream should also be happy with IO[bytes] - see python/typeshed#7843 for some discussion - but I'm a little out of my depth on this part of Python typing.
The following examples will reproduce this mypy error
from zipfile import ZipFile
from construct import Struct, GreedyBytes
s = Struct(
'test' / GreedyBytes
)
with ZipFile('spam.zip') as myzip:
with myzip.open('eggs.txt') as myfile:
parsed = s.parse_stream(myfile)
Changing StreamType = t.BinaryIO to StreamType = t.Union[t.BinaryIO, t.IO[bytes]] in construct-stubs/core.pyi resolves this.
I'm happy to create a PR if that seems like the appropriate solution
Thanks so much for construct-typing :)
I'm parsing a stream from a zip file, and mypy shows the following error
Argument 1 to "parse_stream" of "Construct" has incompatible type "IO[bytes]"; expected "BinaryIO" [arg-type] (11:32)I believe that
parse_streamshould also be happy withIO[bytes]- see python/typeshed#7843 for some discussion - but I'm a little out of my depth on this part of Python typing.The following examples will reproduce this mypy error
Changing
StreamType = t.BinaryIOtoStreamType = t.Union[t.BinaryIO, t.IO[bytes]]in construct-stubs/core.pyi resolves this.I'm happy to create a PR if that seems like the appropriate solution
Thanks so much for construct-typing :)