-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Type checking for Python code #3382
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
7d4414c
52be6ac
7a0bc51
3689281
6c592f3
278ac07
b2c2b83
6e0e8a9
b595248
365a6a5
1db4076
e5fd4c2
cb90015
f13325d
a6bf5aa
44ec379
b9086ce
853eb5a
edbaace
82f8166
c234f9d
648069a
f585773
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,5 +1,14 @@ | ||
| { | ||
| "pythonVersion": "3.10", | ||
| "extraPaths": ["source/pip", "source/widgets/src", "source/qdk_package/src"], | ||
| "include": ["source/qdk_package/qdk"], | ||
| "exclude": [ | ||
| "source/qdk_package/qdk/applications", | ||
| "source/qdk_package/qdk/azure", | ||
| "source/qdk_package/qdk/cirq", | ||
| "source/qdk_package/qdk/simulation", | ||
| "source/qdk_package/qdk/qiskit", | ||
| "source/qdk_package/qdk/qre" | ||
|
Member
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. Do we plan to include this at a later point?
Contributor
Author
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. Yes, in follow-up PRs. |
||
| ], | ||
| "reportMissingModuleSource": "none", // Allow .pyi without .py | ||
| "typeCheckingMode": "basic" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Libraries that need to be installed to run Python static checks. | ||
| matplotlib | ||
| pandas>=2.1 | ||
| pandas-stubs | ||
| pyqir>=0.12.5,<0.13 | ||
|
Member
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. Why do these need to be installed for the checks? Does it need to verify the types from any package your our code may use? (In which case, would it need to ultimately extend to qiskit, cirq, etc.)?
Contributor
Author
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. When typechecker sees import statement and library is not installed, it raises an error (both mypy and pyright).
We can make this choice for every library we import, this is why I created this separate requirements file. I chose to install matplotlib, pandas and pyqir rather than ignoring them. Yes, I intend to ultimately extend it here to use other libraries, like cirq and qiskit, but I want to be able to make this choice for each library. If I see that some library would take a lot of time to install (e.g. cirq that has a lot of dependencies) and is used only in few limited places, I can ignore it or maybe only install type stubs. |
||
| pyright==1.1.410 | ||
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.
The existing
checkflag does JavaScript/TypeScript and Rust. Is there a reason to add a distinct Python check flag than just roll it into the existingcheck(if building a Python package).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.
Yes,
build.py --check-pyin CI workflow for python static checks.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.
If we're going to split it out, I'd lean towards splitting all of them out and then having
checkmean "check all".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.
I talked to @swernli about this and he suggested the same - having an option in build.py to run every check separately, but this can be done in later PR.
This option exists for the following scenario: let's say you did some change to Python and "static Python check" workflow failed. You want to do fixes, verify them locally, push your changes and get workflow green as soon as possible. You do your local changes, run
build.py --check-py, it passes, then you push your changes and the workflow is green.Without this option, there would be no way to run python static checks only.