feat(schematic): evaluate Pyright for type checking in schematic-api
#2845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR sets up a comparison of type checking in
sandbox-api
using both mypy and Pyright. The best of the two will be used in example Python projects likesandbox-py-app
andsandbox-py-lib
.A couple of notes about both linters:
schematic-api
project.Changelog
schematic-api:type-check
References
Notes
About Pyright VS Code extension:
Preview
Note
Here we are type checking the entire
schematic_api
folder instead of the subset of files checked by the taskschematic-api:mypy
.Type checking with mypy
Output:
In strict mode:
Runtime (non-strict mode; the strict mode features virtually the same runtime (data not shown)):
Type checking with Pyright
Output:
In
strict
mode:Runtime (
strict
mode):Observations
schematic_api/
. mypy found 483 errors in strict mode.Comparison by ChatGPT
Here's a comparison table between
mypy
andpyright
, two popular static type checkers for Python:mypy.ini
orsetup.cfg
).pyrightconfig.json
.*.pyi
stub files.strict
mode, plugins.strict
and custom rules, but fewer plugins.@no_type_check
,@type: ignore
, and more for finer control.# pyright: ignore
,type: ignore
comments.flake8
needed for style issues.Overall, both tools are powerful for static type checking in Python. The choice between them often comes down to project requirements, editor preference, and performance needs.