Skip to content

MAINT: Make batch_task_async generic over the task result - #4567

Open
Szymon Kubica (szKubica) wants to merge 1 commit into
microsoft:mainfrom
szKubica:maint/4550-generic-batch-task-async
Open

Szymon Kubica (szKubica) wants to merge 1 commit into
microsoft:mainfrom
szKubica:maint/4550-generic-batch-task-async

Conversation

@szKubica

Copy link
Copy Markdown

Description

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]. Follow-up to #4544 (UA-2 of #4402).

Closes #4550

  • pyrit/prompt_target/batch_helper.py: add the _BatchResult TypeVar and use it for task_func and the return type. The argument side stays Callable[..., ...] because kwargs are built dynamically from task_arguments.
  • pyrit/prompt_normalizer/prompt_normalizer.py: remove the cast("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-unused cast import.
  • pyrit/score/scorer_evaluation/scorer_evaluator.py: remove the equivalent cast("list[list[Score]]", ...) in _score_responses_grouped_async.
  • pyrit/score/scorer.py: both call sites are now statically list[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-assignment override.

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>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 19:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 _BatchResult to 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

@szKubica

Copy link
Copy Markdown
Author

Szymon Kubica (Szymon Kubica (@szKubica)) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT: Make batch_task_async generic over the task result (unsound-assignment follow-up)

2 participants