Fix trailing whitespace and a shadowed gettext _ in AssociationsTool#996
Conversation
The addons-source CI (PR 820) adds a lint step that fails on any tracked Python file carrying trailing whitespace. Three pre-existing files trip it (27 lines total): ArchiveAssist/ArchiveAssist.py (22), and two FilterRules modules (5). Strip the trailing whitespace so the gate can pass; whitespace only, no behavioural change (git diff -w is empty).
_build_with_progress used `for _ in range(batch_size)`, which makes _
a local variable throughout the whole method (Python binds it at compile
time). That shadows the module-level `_ = _trans.gettext`, so:
- the except handler at the top of the method, LOG.error(_("Error
initializing data: %s") % str(e)), runs before the loop assigns _
and raises UnboundLocalError; and
- the in-loop handler LOG.warning(_("Error processing person %s: %s"
% ...)) calls _ after the loop bound it to an int, raising TypeError.
Both fire only on the error paths, so they slipped through. The loop
counter is unused; rename it to _batch_step so _ resolves to the module
gettext everywhere. ruff (E9,F63,F7,F82) is clean on the module.
This also clears the F82x lint error PR 820's ruff gate reports on the
current tree.
My bad, I did not see it during review for #976 |
|
There was a blind change (according to my working branch) on #967 (gramps52) IA pointed out possible issues, but this one was not explicit (there was two locations...), despite matched. |
No worries - it surfaced during my work on a CI for addons-source, so it's doing what it's supposed to. :-) |
Problem
Two pre-existing defects on
maintenance/gramps60that the addon CI pipeline (#820) surfaces the moment its lint gate runs:Trailing whitespace on three tracked Python files (27 lines):
ArchiveAssist/ArchiveAssist.py(22),FilterRules/matcheventfilterrole.py(4),FilterRules/matchparentoffilterfamily.py(1). The pipeline's trailing-whitespace check fails on them.A real latent bug in AssociationsTool:
_build_with_progress()usesfor _ in range(batch_size), which makes_a function-local throughout the method and shadows the module-level_ = _trans.gettext. On the error paths this raisesUnboundLocalError(the_("Error initializing data: %s")handler, which references_before the loop binds it) andTypeError(the in-loop_("Error processing person …")handler, which calls_after the loop bound it to an int). ruffF82flags it.Fix
git diff -wis empty)._batch_stepso_resolves to the gettext function everywhere in the method.Four files, no pipeline/CI files. Splitting these out of #820 so that PR stays pipeline-only; #820's lint lane goes green once this merges and is merged back. Found while running #820's own gates against the tree during an adversarial review of that PR.