Conversation
Importer.extract() computes `lineno` as the 1-based physical line number of the data row: the enumeration starts at `int(header) + bool(names) + 1`. That is the number `metadata()` records via `data.new_metadata(filepath, lineno)`, and it is the number that ends up in the metadata of the extracted transactions. The error path, however, formatted `lineno + 1`, so the same row was reported at two different line numbers depending on whether it parsed or not, and the error pointed one line past the offending row. For a file with a header line and two data rows, an invalid value on the third line was reported as "line 4". Add a regression test that ties the reported line number to the one recorded in the metadata, so the two cannot drift apart again, and one that exercises a file with both skipped header lines and a names row. This change was authored by an AI agent.
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.
Importer.extract()computeslinenoas the 1-based physical line number ofthe data row:
That is also the number
metadata()records throughdata.new_metadata(filepath, lineno), so it is what ends up in the metadata ofthe extracted transactions. The error path, however, formatted
lineno + 1:so the same row was reported at two different line numbers depending on whether
it parsed or not, and the error pointed one line past the offending row.
Reproduced with beancount 3.2.3 on a three-line file (header plus two data rows,
the last one invalid):
The existing
test_report_exceptionencoded the old behaviour (its docfile hastwo lines and the failing row is the second one, but the expected message said
line 3), so its expectation is updated toline 2.Two regression tests are added:
test_report_exception_matches_metadata_linenoextracts a file successfully,remembers the
linenometadata of the last row, then makes that same rowinvalid and requires the reported line number to be the one from the
metadata. This pins the two code paths together rather than hard-coding a
constant, so they cannot drift apart again.
test_report_exception_line_numberingcovers a file that has both skippedheader lines (
header = 1) and a names row, and asserts against the lineindex actually read back from the file.
Without the one-character fix all three tests fail; with it the full suite
(
pytest beangulp examples, 174 tests) passes, andruff check beangulp/ examples/is clean.Disclosure: this change was written by an AI agent. A human is accountable for
the submission and will respond to review comments.