fix: self-assignment no-ops and mutable default argument in usfmerge.py#1158
Open
megahirt wants to merge 1 commit into
Open
fix: self-assignment no-ops and mutable default argument in usfmerge.py#1158megahirt wants to merge 1 commit into
megahirt wants to merge 1 commit into
Conversation
Collaborator
|
@mhosken and @davidg-sil Here's another one where it sounds like the fist is plausible, but I'd rather YOU make the call. |
Collaborator
|
Yes to bug #19, @davidg-sil for bug 18 |
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.
Summary
PARUSERSYNCmerge branch that should be copying fields fromacc[bi]intoacc[i](bug 18){}inscore()that causes scores to accumulate across calls (bug 19)Both are in
python/lib/ptxprint/usfmerge.py.Bug 18 — Self-assignment no-ops in PARUSERSYNC merge
What is broken
Both lines assign a field to itself. The surrounding context (the
PARUSERSYNCbranch) is copying the first element ofacc[bi]intoacc[i]and markingacc[bi]for deletion — a pattern whereacc[i]should inheritbi's position data. The analogous code elsewhere in the function (lines 571–572) correctly reads fromself.acc[bi].Why it matters
The intended copy/merge operation silently does nothing. After the merge,
acc[i]retains its own stale verse and pnum values instead of inheriting them fromacc[bi]. This produces incorrect chunk positioning whenPARUSERSYNCmarkers are present.How it was fixed
Changed both right-hand sides from
self.acc[i]toself.acc[bi], mirroring the correct pattern used earlier in the same function.Bug 19 — Mutable default argument
{}inscore()What is broken
The
{}default is created once at class-definition time and shared across every call that omits theresultsargument. Scores written intoresultson one call persist into the next call, so subsequent invocations see stale data from previous runs.Why it matters
This is the classic Python mutable-default-argument bug. Alignment scores accumulate across multiple
score()calls instead of starting fresh each time, producing incorrect scores for any book processed after the first.How it was fixed
Changed the signature to
results=Noneand added the standard guard at the top of the function body:This creates a fresh dict on each call that doesn't supply one explicitly.
Files changed
python/lib/ptxprint/usfmerge.pyBug reports
bugs/python/bug-18-self-assignment-noop/andbugs/python/bug-19-mutable-default-arg/(local only, not committed)