Open andyalmandhunter opened 6 years ago
FWIW, I think even in python 3, file.read(size)
is supposed to interpret size as a number of bytes.
So as convenient as it is, I'm thinking that the decode
step doesn't really belong in this method.
See https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects
The
decode
step will sometimes raise aUnicodeDecodeError
, I think because it tries to decodenum
bytes from the file at a time, which isn't necessarily a valid utf-8 encoded string even if the full contents of the file is a valid utf-8 encoded string.To reproduce:
This works fine:
This fails: