← Back to Pull requests

CI: use `pyrefly coverage` instead of `basedpyright --verifytypes` #890

Merged
samwgoldman merged 2 files (12 lines) on Sep 23, 2026 17:59 UTC
View on GitHub
samwgoldman samwgoldman commented on Sep 23, 2026 17:54 UTC
Author

Pyrefly already runs in the typecheck job, so this switches the public-API type-completeness gate in the lint job (and the pyright-verify tox env, now pyrefly-coverage) from basedpyright --ignoreexternal --verifytypes optype to pyrefly coverage check --public-only optype. numpy, scipy-stubs, and pandas-stubs already use the same gate.

On master both tools report 100% (pyrefly: 779 of 779 typable symbols). The coverage is the same with numpy 2.0 and 2.5 installed.

Passing optype explicitly matters. Without it, project mode also counts tests/ and examples/ and reports 98.71%.

Mutation testing

To check that the new gate is at least as strict, I applied one regression at a time to optype/inspect.py, exporting new symbols through __all__ where needed. I ran both tools on each, then restored the file:

| Regression | basedpyright --verifytypes | pyrefly coverage --public-only |
|---|---|---|
| Drop a return annotation | fail | fail |
| Drop a parameter annotation | fail | fail |
| Unannotated method parameter on a public class | fail | fail |
| Public constant assigned from an Any-returning call (json.loads(...)) | pass | fail |
| Explicit -> Any return | pass | pass |
| Unannotated but inferable constant (X = 1, X = [1, 2]) | pass | pass |
| Unannotated but inferable class attribute | pass | pass |
| Public alias of an unresolved import | pass | pass |
| Untyped private helper (should pass) | pass | pass |

Pyrefly caught every regression that --verifytypes caught. It also caught a public symbol that silently resolves to Any, which --verifytypes misses.

Speed

Measured locally, with the same machine and environment:

  • basedpyright --ignoreexternal --verifytypes optype: about 1.45 s

  • pyrefly coverage check --public-only optype: about 0.20 s
  • That is roughly 7x faster, measured across 11 runs of each.

    Why not --strict

    --strict also counts Any-resolved annotations as untyped. It would catch the explicit -> Any case above, but today it reports 99.49% (775/779). The only findings are the two __replace__ methods in optype/copy.py:

    optype/copy.py:73: `optype.copy.CanReplace.__replace__` is not fully typed [coverage-partial]
    optype/copy.py:83: `optype.copy.CanReplaceSelf.__replace__` is not fully typed [coverage-partial]
    

    Both use _: Any, *changes: Any on purpose, as the CanReplace docstring explains. So --strict would need either a brittle --fail-under=99.4 threshold or a way to exempt those two signatures. I left it out of this PR.

    Unrelated finding

    Without --public-only, pyrefly flags one untyped symbol in a private module: optype.infer._signature.signature (optype/infer/_signature.py:28). The public gate doesn't count it, but it might be worth annotating.

    Diff: 12 lines (+6 / -6) across 2 files Reviewer: jorenham Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.11 = Change Risk (0.30) × (1 − Review Confidence (0.64)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.30 · 12 lines diff across 2 files
    0.30
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.54 · 2 substantive comment(s)
    0.54
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    63%
    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.153
    Rapid Merge rapid_merge
    0.100
    Real PR Conversation Timeline
    4 items
    jorenham jorenham commented on Sep 23, 2026 17:56 UTC
    Contributor

    Haha awesome, thanks! (I can't believe I forgot about optype haha)

    jorenham jorenham approved these changes on Sep 23, 2026 17:58 UTC
    Approved Reviewer

    Approved these changes.

    jorenham jorenham commented on Sep 23, 2026 17:59 UTC
    Contributor

    Thanks Sam!

    Reviewers
    Assignees
    samwgoldman samwgoldman
    Labels
    risk: low confidence: 63.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: 29.8% (LOW) · Higher = larger blast radius
    29.8%
    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: 63.8% · Lower = rushed or shallow review
    63.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: 10.8% · Safe to merge
    10.8%