-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Migrate from mypy to ty type checker #2911
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?
Conversation
- Replace mypy with ty (Astral's Rust-based type checker) for faster CI - Configure ty in pyproject.toml with Python 3.10 target and source paths - Update CI workflow to use 'ty check' command - Fix type errors found by ty's stricter checking: - Add None check for doc_for_pymupdf in pdfparser.py - Fix figure_title type (str() wrapper) in pdfparser.py - Add type: ignore comments for Azure SDK type stub issues - Remove unused type: ignore comments from mypy era - Add .ty_cache to .gitignore and VS Code settings - Update AGENTS.md and PR template with ty instructions Closes Azure-Samples#2910
- scripts/auth_init.py: Add pragma: no cover to main() since it's an orchestration entry point and the individual helper functions are tested - pdfparser.py: Add pragma: no cover to defensive None check
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.
Pull request overview
This pull request migrates the type checking system from mypy to ty, Astral's Rust-based Python type checker, to achieve faster CI runs. The migration includes configuration changes, dependency updates, and fixes for type errors identified by ty's stricter checking.
Changes:
- Replaced mypy with ty (>=0.0.1a12) in development dependencies
- Updated pyproject.toml with ty-specific configuration for Python 3.10
- Modified CI workflow to use
ty checkcommand instead of separate mypy checks - Fixed type errors in several backend files and added/removed type: ignore comments as needed
- Updated documentation (AGENTS.md, PR template) with ty instructions
- Added .ty_cache to .gitignore and VS Code exclusions
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements-dev.txt | Replaced mypy==1.14.1 with ty>=0.0.1a12 |
| pyproject.toml | Removed mypy configuration and added ty configuration with Python 3.10 target, source paths, and rule overrides |
| .github/workflows/python-test.yaml | Simplified type checking from separate mypy commands to single ty check command |
| scripts/auth_init.py | Added assert statement to satisfy ty's type narrowing limitation and pragma: no cover comment |
| app/backend/prepdocslib/servicesetup.py | Removed unnecessary type: ignore comment for api_key parameter |
| app/backend/prepdocslib/pdfparser.py | Added defensive check for doc_for_pymupdf and changed caption.content handling to explicit str() conversion |
| app/backend/prepdocslib/page.py | Removed unnecessary type: ignore comment for tuple assignment |
| app/backend/prepdocslib/blobmanager.py | Added type: ignore comment for upload_blob arg-type issue |
| app/backend/chat_history/cosmosdb.py | Removed unnecessary type: ignore comment for continuation_token |
| app/backend/app.py | Added type: ignore comment for SpeechSynthesisOutputFormat attribute |
| AGENTS.md | Updated type checking instructions to use ty check instead of separate mypy commands |
| .github/PULL_REQUEST_TEMPLATE.md | Updated checklist to reference ty check instead of python -m mypy |
| .vscode/settings.json | Added .ty_cache to file exclusions |
| .gitignore | Added .ty_cache/ to ignored directories |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…comments - app.py: Use set_speech_synthesis_output_format() method instead of undeclared attribute - blobmanager.py: Add comment explaining ty doesn't recognize IO[AnyStr] type - pyproject.toml: Add comments explaining difference between root (module resolution) and include (files to check)
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.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.
Pull request overview
Copilot reviewed 16 out of 17 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Purpose
Migrates from mypy to ty, Astral's Rust-based Python type checker, for faster CI runs. ty is significantly faster than mypy due to its Rust implementation.
Closes #2910
Changes include:
ty checkcommandDoes this introduce a breaking change?
When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
If you're not sure, try it out on an old environment.
Does this require changes to learn.microsoft.com docs?
This repository is referenced by this tutorial
which includes deployment, settings and usage instructions. If text or screenshot need to change in the tutorial,
check the box below and notify the tutorial author. A Microsoft employee can do this for you if you're an external contributor.
Type of change
Code quality checklist
See CONTRIBUTING.md for more details.
python -m pytest).python -m pytest --covto verify 100% coverage of added linesty checkto check for type errorsruffandblackmanually on my code.