Fix azure-ai-evaluation typing issues for mypy version 1.14.1 compatibility #42055
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.
This PR addresses typing compatibility issues in azure-ai-evaluation that prevent successful type checking with mypy version 1.14.1, which will be merged on 2025-07-14.
Issues Fixed
The following mypy errors have been resolved:
1. Type Annotations (
var-annotated
errors)risk_assessment
variables in_red_team_result.py
validated_prompts
andvalid_prompts_by_category
in_attack_objective_generator.py
session_state
in_conversation.py
tasks
in_adversarial_simulator.py
evaluators_dict
in_safety_evaluation.py
2. Return Type Compatibility (
return-value
errors)to_eval_qr_json_lines()
method return type fromstr
toList[str]
[]
instead of""
3. Assignment Compatibility (
assignment
errors)_get_evaluators()
method by adding proper type annotation4. List Type Casting (
arg-type
errors)list_mean_nan_safe()
function calls in safety evaluationFiles Changed
azure/ai/evaluation/red_team/_red_team_result.py
azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py
azure/ai/evaluation/red_team/_attack_objective_generator.py
azure/ai/evaluation/simulator/_conversation/_conversation.py
azure/ai/evaluation/simulator/_adversarial_simulator.py
Verification
All original mypy 1.14.1 compatibility errors mentioned in the issue have been successfully resolved. The changes are minimal and surgical, focusing only on type safety improvements without altering functionality.
Example of fixes applied:
Fixes #40620.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.