Skip to content

Switch type checking from mypy to Pyrefly (#8182) - #8227

Open
rosspeili wants to merge 2 commits into
quantumlib:mainfrom
rosspeili:switch-to-pyrefly-8182
Open

Switch type checking from mypy to Pyrefly (#8182)#8227
rosspeili wants to merge 2 commits into
quantumlib:mainfrom
rosspeili:switch-to-pyrefly-8182

Conversation

@rosspeili

@rosspeili rosspeili commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Switch type checking from mypy to Pyrefly per 8182, also includes the check/typecheck rename/deprecation from 8225, can close once this lands.

  1. Migrated [tool.mypy] with pyrefly init, then set monorepo search-path to match dev_tools/pypath.
  2. Excluded notebooks (and generated cirq_google/cloud) as discussed on 8182.
  3. Mapped mypy’s follow_imports=silent/skip third-party posture to ignore-missing-imports + replace-imports-with-any for sympy/networkx/pandas/protobuf.
  4. Fixed two first-party issues similar to OpenFermion take (dtype is not None, cast before sorted for Qids).
  5. Added check/typecheck, deprecated check/mypy (remove in v1.8), updated CI / check/all / shellcheck / deps / docs.

notes

  • Left mypy-protobuf / --mypy_out alone (stub generation, not the typechecker CLI).
  • Some Pyrefly error kinds that are much stricter than Cirq’s old silent-import mypy setup are disabled in [tool.pyrefly.errors] for this migration.

Test plan

  • pyrefly check → 0 errors locally
  • black / ruff clean on touched Python
  • pytest on touched modules
  • CI Type check job green

Fixes #8182

Add check/typecheck, deprecate check/mypy, and wire CI/deps/docs.
Migrate config from mypy with monorepo search-path and notebook excludes.
@rosspeili
rosspeili requested a review from a team as a code owner July 26, 2026 14:36
@rosspeili
rosspeili requested a review from viathor July 26, 2026 14:36
@github-actions github-actions Bot added the size: L 250< lines changed <1000 label Jul 26, 2026
@rosspeili

Copy link
Copy Markdown
Contributor Author

Config choices and follow-up

Since pyrefly is stricter than cirq’s previous mypy config (follow_imports=silent on sympy/networkx/pandas/protobuf), after mapping that to replace-imports-with-any, hundreds of first-party diagnostics remained (bad-argument-type, overload/kwargs patterns, etc.) that mypy did not effectively enforce. Per #8182 (“fix or adjust config for low-priority”), those kinds are disabled for now so the tool switch stays green without cirq-wide annotation rewrite.

Same idea as the OpenFermion pyrefly migration (#1433): migrate the checker first, tighten selectively later.

Suggested follow-up unless otherwise advised

  1. Re-enable error kinds one at a time (start with bad-return / missing-attribute).
  2. Fix or narrowly # type: ignore real first-party issues.
  3. Prefer that over expanding replace-imports-with-any.

Happy to open that follow-ups after this lands, or adjust the disable list here if you’d rather tighten in this PR.

@pavoljuhas @mhucka, this also covers #8225’s check/typecheck / deprecate-check/mypy bits.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (726eed6) to head (a488ffd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8227   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files        1118     1118           
  Lines      101667   101667           
=======================================
  Hits       101261   101261           
  Misses        406      406           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch from mypy to Pyrefly

1 participant