New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
codecs.StreamReader.read behaves differently from regular files #58680
Comments
For regular files, a read() call without arguments will read until EOF. codecs.StreamReader does its own buffering, and if there are characters in the buffer, a read() call will be satisfied from the buffer without an attempt to read the rest of the file. This discrepancy causes certain code that worked with regular open() fail if codecs.open() is substituted. The easiest way to reproduce this is to first call readline() and then read(). Since readline() can't know how many characters are on the line, it will almost always leave some characters in the buffer, triggering the problem with read(). |
Oh, yet another bug in in codecs.StreamReader. I should add it to the PEP :-) Use io.TextIOWrapper (open) instead of codecs.StreamReader (codecs.open), it's bugfree :-) |
Just got this behavior, with readlines(), which is unsurprising since it internally uses read() as described in the original bug report. The break on line 468 of codecs.py seems to be the problem, it fixes it if I remove this conditional locally. http://hg.python.org/cpython/file/f6a207d86154/Lib/codecs.py#l466 I may be overlooking something, but I would assume this should be checking if the character buffer extends to the EOF of the underlaying stream at this point? As stated before can be reproduced by: |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: