Skip to content
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

ci: Add Pyright static type checking workflow #1195

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

KarimAziev
Copy link
Contributor

This pull request introduces Pyright, a static type-checking tool for Python, into the GitHub Actions CI pipeline.

As part of addressing issue #1192, this addition encourages gradual improvements in type annotations while providing developers with immediate feedback on type-related issues.

At this stage, the pipeline warns about type issues and doesn’t enforce strict checking. This is intentional to allow gradual type annotation improvements over time.

@davidplowman davidplowman merged commit d15fde1 into raspberrypi:next Jan 23, 2025
5 checks passed
@davidplowman
Copy link
Collaborator

davidplowman commented Jan 23, 2025

Thanks, that's really great! One further thought... do you know if it would be possible to install this check as part of our pre-commit hook? Not essential, I guess, but it might be nice to be told about errors before creating a pull request.

Edit: Ah, I see. Looks like I can add it to the .pre-commit-config.yaml file. I'll try that!

@KarimAziev
Copy link
Contributor Author

Yes, you're correct that it is possible to integrate Pyright into the pre-commit hooks via the .pre-commit-config.yaml file. However, it might be too early to consider adding it to the pre-commit workflow at this stage.

When I initially added Pyright to the CI for this repository, it detected around 400 type-related issues. To avoid blocking progress, these issues were downgraded to warnings for now, providing visibility without enforcing strict type-checking.

Adding Pyright as a strict pre-commit check at this point might create unnecessary friction for contributors, as many existing warnings could interfere with commit workflows. An alternative approach could be to encourage developers to configure their IDEs to use Pyright, allowing them to see and fix warnings incrementally while working on the codebase.

A potential strategy could involve enabling stricter checks incrementally. For example, starting with reportReturnType as an error (which would raise ~20 manageable errors) could help enforce type safety gradually without overwhelming contributors.

Once the majority of issues are addressed and warnings are cleaned up, it might make sense to revisit the idea of adding Pyright to the pre-commit hooks as a way to enforce stricter type-checking for new changes. For now, though, an incremental improvement process seems more practical.

@davidplowman
Copy link
Collaborator

Yes, those are good points. Maybe I'll just start using it locally, figure out how to start enabling just a few things, and see how it goes for a bit. Thanks!

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.

2 participants