If passing a buffer to TextIOWrapper
(or maybe for completeness, other cases as well?), what are the possible consequences (in terms of memory usage, exceptions, other?) of the buffer not respecting the n
parameter passed to its read
method?
Say in the below example, it all appears to work fine:
from io import IOBase, TextIOWrapper
bytes_iter = (
b'some',
b'bytes',
b'maybe a lot' + b'-' * 10000
)
it = iter(bytes_iter)
class FileLikeObj(IOBase):
def readable(self):
return True
def read(self, size=-1):
print('Asked for:', size)
return next(it, b'')
text_io = TextIOWrapper(FileLikeObj(), encoding='utf-8', newline='')
for line in text_io:
print('Found a line')
even though it returns more than the 8192 bytes that (for me) are always asked for, but is this fine in general?
This is inspired by/related to the answer at https://stackoverflow.com/a/70639580/1319998, and I'm trying to determine if the buffer should respect n
or not