Closed
Description
I'm using readinto
on a binary file in my project with static typing and I have a problem with typing.BinaryIO
class.
Sample code reproducing error:
# foo.py
buf = bytearray(16)
with open('/dev/random', 'rb') as h:
h.readinto(buf)
print(buf)
Script executes fine, but mypy complains about missing method "readinto".
$ python3 -V
Python 3.6.5
$ python3 -m mypy -V
mypy 0.600
$ python3 foo.py
bytearray(b'\x96\x91m\xe0\x8c\xcb\xa4h\xea\xe3.\x0c\xba\x04L7')
$ python3 -m mypy foo.py
foo.py:3: error: "BinaryIO" has no attribute "readinto"
The docs read as following:
Even though IOBase does not declare read(), readinto(), or write() because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise a ValueError (or UnsupportedOperation) when operations they do not support are called.
source
I've checked and this is already marked as a TODO typing.pyi
, so I'm just bumping the issue.
Line 432 in 97d9f2e