Repository navigation
Conversation
Config choices and follow-upSince pyrefly is stricter than cirq’s previous mypy config ( Same idea as the OpenFermion pyrefly migration (#1433): migrate the checker first, tighten selectively later. Suggested follow-up unless otherwise advised
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8227 +/- ##
==========================================
- Coverage 99.59% 99.59% -0.01%
==========================================
Files 1125 1127 +2
Lines 103250 103414 +164
==========================================
+ Hits 102829 102992 +163
- Misses 421 422 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Discussed in Cirq Cynq 2026-09-02: We'll try to do this before 1.8. |
|
@mhucka you want me to rebase and clean up any arising conflicts or you'll do during merge? |
|
@rosspeili - please hold on with the rebase. I will merge the main branch myself. |
pavoljuhas
left a comment
There was a problem hiding this comment.
As it is, the PR removes mypy and suppresses most pyrefly errors - effectively leaving the code without type check. Let us loosely follow the advice at https://pyrefly.org/en/docs/migrating-from-mypy/#3-handle-the-new-errors-and-drop-mypy instead, i.e., please restore mypy and keep it active in the CI. For the initial pyrefly config please generate and commit the "pyrefly-baseline.json" file and configure pyrefly to use it as its baseline.
This will enforce pyrefly for any changed code. We can then gradually work on errors suppressed in pyrefly-baseline.json until it is not needed anymore. Once we get there, we can remove mypy and use the pyrefly only.
| @@ -1,7 +1,7 @@ | |||
| #!/usr/bin/env bash | |||
|
|
|||
| ################################################################################ | |||
| # Runs mypy on the repository. | |||
There was a problem hiding this comment.
Please restore to the main version. We will keep mypy around for the time of transition.
| @@ -154,7 +154,10 @@ def __init__( | |||
|
|
|||
| @property | |||
| def qubits(self) -> tuple[cirq.Qid, ...]: | |||
| return cast(tuple['cirq.Qid', ...], tuple(sorted(self.device_graph.vertices))) | |||
| return cast( | |||
There was a problem hiding this comment.
Please revert, this does not make a difference at this point.
| @@ -13,4 +13,4 @@ repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) || exit $? | |||
| cd "${repo_dir}" || exit $? | |||
|
|
|||
| source dev_tools/pypath || exit $? | |||
| mypy "$@" . | |||
There was a problem hiding this comment.
Please update to run both mypy and typecheck, for example,
mypy "$@" . && pyrefly checkFor now we can ignore the command-line arguments for pyrefly and add them there after dropping mypy.
| @@ -0,0 +1,6 @@ | |||
| # Type checking tool | |||
| pyrefly==1.2.0 | |||
There was a problem hiding this comment.
Please add mypy==2.1.0 back here.
| @@ -49,6 +49,7 @@ def run( | |||
| 'pylint', | |||
| 'env', | |||
| 'pytest', | |||
| 'pyrefly', | |||
There was a problem hiding this comment.
Not necessary, please revert.
| @@ -163,12 +163,12 @@ This script uses the `grpcio-tools` package to generate the Python proto API. | |||
|
|
|||
| There are a few options for running continuous integration checks, varying from easy and fast to slow and reliable. | |||
|
|
|||
| The simplest way to run checks is to invoke `pytest`, `pylint`, or `mypy` for yourself as follows: | |||
| The simplest way to run checks is to invoke `pytest`, `pylint`, or `pyrefly` for yourself as follows: | |||
There was a problem hiding this comment.
Please revert this file, for the transition we will use mypy as the main type checker.
| [tool.mypy] | ||
| exclude = [ | ||
| '/setup\.py', | ||
| 'cirq-google/cirq_google/cloud/', |
There was a problem hiding this comment.
Please restore the mypy section.
|
|
||
| # Checks that are much stricter than mypy under Cirq's silent-import setup. | ||
| # Tracked for follow-up tightening after the tool switch. | ||
| [tool.pyrefly.errors] |
There was a problem hiding this comment.
This would essentially disable typechecking. For consistency with our internal config, please use
redundant-cast = "error"
unused-type-ignore = "error"
Instead of disabling most errors, we should generate and commit the "pyrefly-baseline.json" file following the advice at https://pyrefly.org/en/docs/migrating-from-mypy/#3-handle-the-new-errors-and-drop-mypy. When pyrefly checks against the baseline file, it will flag typing errors in any new code. We can then gradually work on fixing the errors in the baseline file so it is eventually not necessary and can be removed. At that point we can drop mypy and use pyrefly only.
| "**/setup.py", | ||
| "**/cirq-google/cirq_google/cloud/**", | ||
| "**/*.ipynb", | ||
| "**/docs/**", | ||
| "**/__pycache__/**", | ||
| "**/.venv/**", | ||
| "**/venv/**", | ||
| "**/node_modules/**", |
There was a problem hiding this comment.
Are all of these needed? Please keep only the patterns which may match some files in the search-path above.
Add check/typecheck, deprecate check/mypy, and wire CI/deps/docs. Migrate config from mypy with monorepo search-path and notebook excludes.
Restore mypy as the primary type checker during the Pyrefly transition. Run both mypy and pyrefly in check/typecheck, commit pyrefly-baseline.json so only new/changed code must satisfy Pyrefly, and revert docs to reference mypy per maintainer feedback.
3476384 to
53ee0cc
Compare
Fixes check/misc EOF whitespace failure in CI.
Add stim to pyrefly ignore-missing-imports (matching mypy) and baseline entries for numpy typing errors seen in CI on Python 3.11.
|
Hey @pavoljuhas, all points addressed the best I could. Will tweak if CI has issues. Let me know how this looks, and any feedback and directional tips more than welcome <3 |
Drop the ANSI red prefix and EXIT trap; mypy and pyrefly already colorize their own output when FORCE_COLOR is set.
|
Good catch @mhucka and yes, that would have turned all mypy/pyrefly output red until exit. Removed in last commit as both tools already colorize their own output via |
Switch type checking from mypy to Pyrefly per 8182, also includes the
check/typecheckrename/deprecation from 8225, can close once this lands.[tool.mypy]withpyrefly init, then set monoreposearch-pathto matchdev_tools/pypath.cirq_google/cloud) as discussed on 8182.follow_imports=silent/skipthird-party posture toignore-missing-imports+replace-imports-with-anyfor sympy/networkx/pandas/protobuf.dtype is not None, cast beforesortedfor Qids).check/typecheck, deprecatedcheck/mypy(remove in v1.8), updated CI /check/all/ shellcheck / deps / docs.notes
mypy-protobuf/--mypy_outalone (stub generation, not the typechecker CLI).[tool.pyrefly.errors]for this migration.Test plan
pyrefly check→ 0 errors locallyFixes #8182