Repository navigation
MAINT: Make batch_task_async generic over the task result - #4567
Open
Szymon Kubica (szKubica) wants to merge 1 commit into
Open
Szymon Kubica (szKubica) wants to merge 1 commit into
Szymon Kubica (szKubica) wants to merge 1 commit into
Conversation
batch_task_async now takes task_func: Callable[..., Awaitable[_BatchResult]] and returns list[_BatchResult], so callers get the element type inferred from the task instead of list[Any]. This removes the casts in PromptNormalizer.send_prompt_batch_to_target_async and ScorerEvaluator._score_responses_grouped_async. Annotation-only change, no runtime behavior change. Closes microsoft#4550 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The batch-task result typing update has no active review issues.
No open issues 🎉
What changed in this PR
Makes batch_task_async generic over its task’s result type, improving type inference for prompt normalization and scoring. This follows up on #4544 and addresses #4550 without changing runtime behavior.
Changes:
- Use
_BatchResultto connect the callback’s awaited result type to the returned list. - Remove redundant result casts from callers.
- Clarify the scorer’s flattening comment.
| File | Description |
|---|---|
pyrit/score/scorer.py |
Updates only the comment describing score-list flattening. |
pyrit/score/scorer_evaluation/scorer_evaluator.py |
Returns the typed batch result directly, removing a cast. |
pyrit/prompt_target/batch_helper.py |
Adds generic callback, return, and result-list annotations. |
pyrit/prompt_normalizer/prompt_normalizer.py |
Removes the redundant result cast, explanatory comment, and unused import. |
Review effort: Balanced
Author
@microsoft-github-policy-service agree |
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.
Description
batch_task_asyncnow takestask_func: Callable[..., Awaitable[_BatchResult]]and returnslist[_BatchResult], so callers get the element type inferred from the task instead oflist[Any]. Follow-up to #4544 (UA-2 of #4402).Closes #4550
pyrit/prompt_target/batch_helper.py: add the_BatchResultTypeVar and use it fortask_funcand the return type. The argument side staysCallable[..., ...]because kwargs are built dynamically fromtask_arguments.pyrit/prompt_normalizer/prompt_normalizer.py: remove thecast("list[Message]", ...)added in MAINT: Fix ty unsound-assignment findings in executor, scenario, converter and prompt_normalizer (UA-2) #4544, its comment, and the now-unusedcastimport.pyrit/score/scorer_evaluation/scorer_evaluator.py: remove the equivalentcast("list[list[Score]]", ...)in_score_responses_grouped_async.pyrit/score/scorer.py: both call sites are now staticallylist[list[Score]]; replace the comment that documented that type with one describing the flattening.Annotation-only change: no runtime behavior change, no new entries in the temporary
unsound-assignmentoverride.