-
I have been using pyright for quite some time in my projects using the pre-commit configuration from the documentation. I wanted to ask if it is possible to make pyright check only python files included in the current commit instead of checking all python files that exist in the project? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I suppose you could create a script that dynamically writes a new pyrightconfig.json file and specifies only the newly-committed Python files in the "include" section. However, I wouldn't recommend that approach for CI because it will skip type checking for any modules that depend on (i.e., directly or indirectly import from) the newly-committed files. Pyright also has a "watch mode" where it will run continuously and analyze files that have changed on disk. In this mode, it's able to track dependencies between files, so it doesn't suffer from the problem I mentioned above. However, this mode isn't generally used for CI because CI doesn't run continuously and typically relies on exit codes to determine whether the analysis succeeded or failed. |
Beta Was this translation helpful? Give feedback.
-
What will be needed in pyright to implement the file checking using the command line arguments? Pre-commit can provide the changed files since other hooks already implement this behavior. Would this be included in the mainline if someone fixed it? |
Beta Was this translation helpful? Give feedback.
-
The way I handle this is just remove My personal experience I ended up making a wrapper script for mypy/pyright to do relative checks. Enforcing 0 type errors in a codebase that came to me untyped with 10s of thousands of errors (mostly missing types) wasn't doable so I opted to have CI measure the change in type errors and required each PR to decrease (relative to master) the number of type errors by 5 (number arbitrarily picked). Even file level wise it'd have been hard as some files had 100s of type errors back then. It still got some push back, but people were persuaded to accept it and months later codebase has fixed most type errors. |
Beta Was this translation helpful? Give feedback.
I suppose you could create a script that dynamically writes a new pyrightconfig.json file and specifies only the newly-committed Python files in the "include" section. However, I wouldn't recommend that approach for CI because it will skip type checking for any modules that depend on (i.e., directly or indirectly import from) the newly-committed files.
Pyright also has a "watch mode" where it will run continuously and analyze files that have changed on disk. In this mode, it's able to track dependencies between files, so it doesn't suffer from the problem I mentioned above. However, this mode isn't generally used for CI because CI doesn't run continuously and typically relies on exit code…