Skip to content

Type checking for Python code - #3382

Merged
fedimser merged 36 commits into
mainfrom
fedimser/mypy-1
Jul 14, 2026
Merged

Type checking for Python code#3382
fedimser merged 36 commits into
mainfrom
fedimser/mypy-1

Conversation

@fedimser

@fedimser fedimser commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

This PR:

  • Adds an option to run python static checks using build.py. Currently it only runs type checks using pyright, but more static checks (line length, linter, formatter) can be added here.
  • Adds a new CI workflow that installs minimal requirements and runs the static checks.
  • Fixes code to make static checks pass.

Notes:

  • I only check Python code in source/qdk_package/qdk.
  • Type checking requires different dependencies than tests, so I created a new file check_requirements.txt that includes minimal dependencies that are required to run static checks. This minimizes setup time for CI workflow.

The type checking can be done in multiple ways:

  • pyright - runs pyright directly.
  • ./build.py --check-py - recommended. This installs required dependencies and runs mypy, and doesn't do anything else. If this passes locally, it's guaranteed that it will pass on CI.
  • python ./build.py --check-py --no-check-prereqs - like above, but skips checking prerequisites (like wasm) which are irrelevant for Python. This is used in the CI workflow.
  • Run build.py in a way that includes building qdk and doesn't disable checks. This includes build.py --qdk and build.py with no arguments.

Missing checks (will be added in follow-up PRs):

  • If we remove 6 excluded modules and specify "reportMissingParameterType": "error" and "typeCheckingMode": "strict" in pyrightconfig.json, we get 2745 errors. I plan to gradually fix them in a series of PRs.

@fedimser
fedimser marked this pull request as ready for review June 24, 2026 21:10
Comment thread pyrightconfig.json
@fedimser
fedimser requested review from amcasey, billti and msoeken July 10, 2026 15:51
Comment thread source/qdk_package/qdk/_native.pyi Outdated
Comment thread source/qdk_package/qdk/_interpreter.py Outdated
Comment thread source/qdk_package/qdk/openqasm/_run.py Outdated
Comment thread source/qdk_package/qdk/openqasm/_circuit.py Outdated
Comment thread source/qdk_package/qdk/openqasm/_estimate.py Outdated
Comment thread source/qdk_package/qdk/_context.py Outdated
Comment thread source/qdk_package/qdk/_native.pyi
Comment thread .github/workflows/ci.yml Outdated
@fedimser
fedimser added this pull request to the merge queue Jul 14, 2026
Merged via the queue into main with commit b8d2cee Jul 14, 2026
13 checks passed
@fedimser
fedimser deleted the fedimser/mypy-1 branch July 14, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants