Repository navigation
fix: read lines as bytes in ReadableFile.readline and readlines - #832
Open
jayhemnani9910 wants to merge 2 commits into
Open
jayhemnani9910 wants to merge 2 commits into
jayhemnani9910 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
readline()andreadlines()read into aString, so any line that is not valid UTF-8 raises:Both methods return
Bytes, as the type stubs say, so they should work on any bytes. Latin-1 and cp1252 CSVs or logs, and binary files with newlines, all fail today.read()on the same file works. The fsspec layer uses this reader, so iterating over a file opened withFsspecStorefails the same way.readlines()also pushes the line before checking for EOF, so it always ends with an extrab'', and a JSONL loop over the result breaks on the last item.Both now use
read_until(b'\n', ...)into aVec<u8>, andreadlines()stops at EOF before adding a line. The same applies to thehintbranch.Testing: added
test_readline_non_utf8andtest_readlines_no_trailing_empty_linetotests/test_buffered.py. Both fail on main and pass with the change.pytest testspasses (474 passed, 2 xfailed), andcargo fmt --checkand clippy show nothing new inbuffered.rs.