-
Notifications
You must be signed in to change notification settings - Fork 24
Add mypy type checking to pre-commit hooks #18
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
Conversation
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
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 PR adds mypy static type checking to the project's pre-commit hooks to enforce type hints across the codebase. The implementation includes minimal mypy configuration that requires type annotations on all function definitions.
Key changes:
- Added mypy as a pre-commit hook using v1.14.1
- Configured mypy in pyproject.toml with strict typing requirements (
disallow_untyped_defs = true) - Added missing return type annotation to test function
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
.pre-commit-config.yaml |
Added mypy hook configuration for static type checking |
pyproject.toml |
Added mypy configuration section with Python 3.9 target and strict typing rules |
test/test_hello.py |
Added -> None return type annotation to test_hello() function |
README.md |
Updated documentation to reflect mypy enforcement via pre-commit hooks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Static type checker | ||
| rev: v1.14.1 | ||
| hooks: | ||
| - id: mypy |
Copilot
AI
Jan 8, 2026
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 mypy pre-commit hook may not work correctly with this project's src/ layout without additional configuration. When mypy runs via pre-commit, it needs to know about the package structure. Consider adding either:
- An
argsparameter with--namespace-packagesand--explicit-package-bases, or - An
additional_dependenciesparameter if the package needs to be installed
For a src/ layout, you typically need to add args: [--namespace-packages, --explicit-package-bases] to ensure mypy can properly resolve imports from the sandbox package.
| - id: mypy | |
| - id: mypy | |
| args: [--namespace-packages, --explicit-package-bases] |
PR Checklist
Changes
Adds mypy type checking as a pre-commit hook with minimal configuration enforcing typed function definitions.
Configuration in
pyproject.toml:python_version = "3.9"- matches minimum supported versiondisallow_untyped_defs = true- enforces type hints on all functionswarn_return_any = true- warns onAnyreturnswarn_unused_configs = true- validates configPre-commit hook:
pre-commit/mirrors-mypyv1.14.1Code updates:
test_hello()to include-> Nonereturn type annotationOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.