fix(attempt): default reverse_translation_outputs to a list - #2041
Open
feiiiiii5 wants to merge 1 commit into
Open
fix(attempt): default reverse_translation_outputs to a list#2041feiiiiii5 wants to merge 1 commit into
feiiiiii5 wants to merge 1 commit into
Conversation
The Attempt constructor defaulted reverse_translation_outputs to an empty dict while every production caller assigns a list of Optional[Message] (probes/base.py, probes/atkgen.py). This type drift made outputs_for(lang) return a dict for translated runs that never populated the field, so detectors iterating the result saw string keys instead of messages and could raise AttributeError; as_dict() would also serialize dict keys. Align the default with the documented type: an empty list. Callers and serialization already expect list semantics, and empty list preserves the falsy behavior of the old default. Adds regression tests for the default value, outputs_for() behavior when reverse_translation_outputs is unset, and serialization round-trip of Message/None entries. Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
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.
Root Cause
Attempt.__init__defaultedreverse_translation_outputsto{}while the docstring describes a list and every production caller assigns a list ofOptional[Message](_postprocess_attemptingarak/probes/base.py,probes/atkgen.py). For translated runs that never populate the field,outputs_for(lang)therefore returned an empty dict: detectors that iterate the result (e.g.garak/detectors/base.py) saw string keys instead of messages and could raiseAttributeErroronoutput.text, andas_dict()likewise iterated dict keys when serializing the attempt.Fix
Default
reverse_translation_outputsto[], matching the documented type and all existing callers, and correct the docstring toList[Optional[Message]](the list legitimately containsNonefor missing generator outputs). The empty list preserves the falsy behavior of the old default, so no caller relying on truthiness changes behavior.Test
test_reverse_translation_outputs_defaults_to_list: the default is a list, not a dict.test_outputs_for_unset_reverse_translation_returns_empty_list:outputs_for()returns the original outputs for the matching language and[]for a translated language when the field was never populated.test_reverse_translation_outputs_as_dict_round_trip:Message/Noneentries serialize viaas_dict()and can be reconstructed field-for-field.pytest tests/test_attempt.py→ 26 passed;tests/langservice/probes/test_probes_base.pypostprocess tests → 5 passed. (Fulltests/langservice/detectorssuites require Hugging Face model downloads and were not run to completion locally.)Diff scope
2 files, +47/-2:
garak/attempt.py,tests/test_attempt.py.AI Disclosure
AI-assisted implementation and regression tests; the type-semantics decision (all callers already assign lists; empty list preserves falsy behavior) was human-reviewed before submission.