-
Notifications
You must be signed in to change notification settings - Fork 17
Add type checking with ty
#481
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
|
@ziotom78 @paganol I think this is ready for review. Types are checked both at CI level within the code-style check and I added a pre-commit hook to check them at commit. Along the way, the checker highlighted real sources of bugs that weren't caught by tests (great!), as missing methods, wrong types with wrong operators, and many others. Also, I think it will be extremely useful to track architectural changes as the new A limitation seems to be that Note that I excluded from type checks these folders:
Let me know what you think of this. |
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 adds the ty type checker (version 0.0.9) to the project to perform automatic type-checking. The PR includes configuration for ty in pyproject.toml, integration with pre-commit hooks and CI workflows, and numerous type annotation improvements and bug fixes across the codebase.
Key changes:
- Addition of
tyas a development dependency with appropriate configuration - Type annotation improvements using modern Python syntax (e.g.,
int | Noneinstead ofOptional[int]) - Fixes for type-related issues including proper use of assertions and getattr patterns
- Bug fixes discovered during type checking (typo in
allow_pickle, incorrect variable reference in MBS)
Reviewed changes
Copilot reviewed 50 out of 51 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Added ty 0.0.9 dependency with platform-specific wheels |
| pyproject.toml | Added ty configuration and development dependency |
| .pre-commit-config.yaml | Added pre-commit hook for ty type checking |
| .github/workflows/codestyle.yml | Added CI check for ty |
| litebird_sim/simulations.py | Extensive type annotations, getattr usage, assertions |
| litebird_sim/observations.py | Dynamic attribute declarations, type annotations |
| litebird_sim/spherical_harmonics.py | Union type syntax improvements |
| litebird_sim/spacecraft.py | Type annotations and assertions |
| litebird_sim/mapmaking/destriper.py | Type annotations, datetime.now with timezone |
| litebird_sim/mbs/mbs.py | Fixed typo (allow_pickle) and variable reference bug |
| test/* | Type annotation improvements in test files |
| notebooks/* | Updated with getattr patterns and type annotations |
| Various other modules | Consistent type annotation improvements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Giacomo, thank you so much for having undertook this ordeal! I know this must have been tedious work, especially considering the broad extent of the changes. It’s impressive to see how many inconsistencies you’ve managed to fix. I’m particularly pleased to see that Regarding the specific changes:
I have one technical curiosity: in several places, you switched to Looking ahead, this PR makes me think of two aspects of our workflow:
Excellent work. On my side, this should be merged ASAP, so that people can rebase their copy on this. |
This PR attempts adding
tyto perform automatic type-checking.Right now, this the situation in terms of errors detected by
ty[rule: number of violations] (-> remaining after edit):Thus, this will require some time.