Skip to content

Conversation

@pamelafox
Copy link
Collaborator

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:

  • Replace mypy with ty in requirements-dev.txt
  • 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 (pdfparser.py, app.py, blobmanager.py)
  • 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

Does 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.

[ ] Yes
[x] No

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.

[ ] Yes
[x] No

Type of change

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

Code quality checklist

See CONTRIBUTING.md for more details.

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran ty check to check for type errors
  • I either used the pre-commit hooks or ran ruff and black manually on my code.

- 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
Copy link
Contributor

Copilot AI left a 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 check command 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)
Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

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.

Task: Move from mypy to astral ty

1 participant