Repository navigation
Switch type checking from mypy to Pyrefly (#8182) #8227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
487a607
bcf78d9
53ee0cc
bd9748a
bc21ba5
6eccdbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| -r mypy.txt | ||
| -r typecheck.txt | ||
| -r pytest.txt | ||
| -r format.txt | ||
| -r pylint.txt | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Type checking tools (mypy during transition; Pyrefly with baseline). | ||
| mypy==2.1.0 | ||
| pyrefly==1.2.0 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
|
|
||
| # Packages with stub types for various libraries | ||
| types-protobuf>=6.32.1, <8.0 | ||
| types-requests~=2.32 | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Full typecheck environment with Cirq modules installed. | ||
| # Used by CI Type check job. | ||
|
|
||
| -r deps/cirq-all.txt | ||
| -r deps/typecheck.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ extend_skip = ["__init__.py"] | |
| extend_skip_glob = ["*_pb2.py"] | ||
|
|
||
|
|
||
|
|
||
| [tool.mypy] | ||
| exclude = [ | ||
| '/setup\.py', | ||
|
|
@@ -342,3 +343,82 @@ select = [ | |
|
|
||
| [tool.ruff.lint.per-file-ignores] | ||
| "*.ipynb" = ["E402", "PLW0406"] | ||
|
|
||
| # Migrated from [tool.mypy] via `pyrefly init`. Cirq is a multi-package | ||
| # monorepo; search-path mirrors `source dev_tools/pypath` for imports. | ||
| [tool.pyrefly] | ||
| preset = "legacy" | ||
| # Match mypy defaults: do not aggressively check unannotated defs. | ||
| check-unannotated-defs = false | ||
| infer-return-types = "never" | ||
| # Respect leftover `# type: ignore` comments during migration. | ||
| permissive-ignores = true | ||
| disable-search-path-heuristics = true | ||
| search-path = [ | ||
| ".", | ||
| "cirq-aqt", | ||
| "cirq-core", | ||
| "cirq-google", | ||
| "cirq-ionq", | ||
| "cirq-pasqal", | ||
| "cirq-web", | ||
| ] | ||
| project-excludes = [ | ||
| "**/setup.py", | ||
| "**/cirq-google/cirq_google/cloud/**", | ||
| "**/*.ipynb", | ||
| "**/node_modules/**", | ||
|
Comment on lines
+367
to
+370
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all of these needed? Please keep only the patterns which may match some files in the |
||
| ] | ||
| baseline = "pyrefly-baseline.json" | ||
| ignore-missing-imports = [ | ||
| "__main__", | ||
| "google.api_core.*", | ||
| "google.auth.*", | ||
| "google.cloud.*", | ||
| "google.colab.*", | ||
| "google.oauth2.*", | ||
| "google.protobuf.*", | ||
| "qsimcirq", | ||
| "IPython.*", | ||
| "ipython.*", | ||
| "_pytest.*", | ||
| "absl.*", | ||
| "astroid.*", | ||
| "cachetools.*", | ||
| "filelock.*", | ||
| "ipywidgets.*", | ||
| "matplotlib.*", | ||
| "mpl_toolkits.*", | ||
| "networkx.*", | ||
| "pandas.*", | ||
| "ply.*", | ||
| "proto.*", | ||
| "pylatex.*", | ||
| "pylint.*", | ||
| "pytest.*", | ||
| "qiskit.*", | ||
| "quimb.*", | ||
| "ruamel.*", | ||
| "scipy.*", | ||
| "setuptools.*", | ||
| "stim", | ||
| "stimcirq.*", | ||
| "sympy.*", | ||
| "tensorflow_docs.*", | ||
| "tqdm.*", | ||
| ] | ||
| # Protobuf / heavy stub-poor libs: mypy used follow_imports=silent/skip. | ||
| replace-imports-with-any = [ | ||
| "google.protobuf", | ||
| "google.protobuf.*", | ||
| "sympy", | ||
| "sympy.*", | ||
| "networkx", | ||
| "networkx.*", | ||
| "pandas", | ||
| "pandas.*", | ||
| ] | ||
|
|
||
| [tool.pyrefly.errors] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would essentially disable typechecking. For consistency with our internal config, please use 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. |
||
| redundant-cast = "error" | ||
| unused-type-ignore = "error" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update to run both mypy and typecheck, for example,
For now we can ignore the command-line arguments for pyrefly and add them there after dropping mypy.