← Back to Pull requests

[python] Add type hints to plotting, tracker, SHAP and eval metric tests #12905

Closed
unknown closed this pull request without merging on Nov 29, 2026 06:04 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 02:48 UTC
Author

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.py and
tests/python/test_eval_metrics.py to 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_defs is enabled):

  • test_plotting.py: add -> None to two test methods.

  • test_tracker.py: annotate the executor, worker arguments and test parameters; test_rank_assignment now asserts

  • that the task ID is a str and that the regex matched before using them.
  • test_eval_metrics.py: annotate the custom metrics and tests; declare beta in test_gamma_lik as

  • Union[int, np.ndarray] because the variable is reused.
  • test_shap.py: annotate the reference SHAP helpers. The parsed tree nodes get a small TreeNode TypedDict, and

  • indexing a node goes through a local node variable with cast because the list may hold None. The regex match for
    leaf 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.

    Diff: 208 lines (+156 / -52) across 2 files Reviewer: trivialfis Review duration: 195m
    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
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%
    Repository