[python] Add type hints to plotting, tracker, SHAP and eval metric tests #12905
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.36) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 208 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.320
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12905"
general
weight: 0.35
trivialfis
Part of #6496, following the same pattern as #12838 and #12901.
This PR adds
tests/python/test_plotting.py,tests/python/test_tracker.py,tests/python/test_shap.pyandtests/python/test_eval_metrics.pyto the list of files checked by mypy in CI (ops/script/type_check_python.py).Changes needed for the files to pass mypy (
disallow_untyped_defsis enabled):test_plotting.py: add-> Noneto two test methods.test_tracker.py: annotate the executor, worker arguments and test parameters;test_rank_assignmentnow assertsthat the task ID is a
strand that the regex matched before using them.test_eval_metrics.py: annotate the custom metrics and tests; declarebetaintest_gamma_likasUnion[int, np.ndarray]because the variable is reused.test_shap.py: annotate the reference SHAP helpers. The parsed tree nodes get a smallTreeNodeTypedDict, andindexing a node goes through a local
nodevariable withcastbecause the list may holdNone. The regex match forleaf lines is also a type-only
cast.The expected values and existing assertions are unchanged.
Verified locally:
cd python-package && mypy ../tests/python/test_plotting.py ../tests/python/test_tracker.py ../tests/python/test_shap.py ../tests/python/test_eval_metrics.py
# each file and ../ops pass on this branch (mypy 2.4.1); master reports errors for these four files
pytest tests/python/test_plotting.py tests/python/test_tracker.py tests/python/test_shap.py tests/python/test_eval_metrics.py
# 45 passed, 9 skipped (same counts as master)
pre-commit run(ruff check / ruff format) passes on the changed files.