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

Add pyright as a pre-commit check #2115

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Add pyright as a pre-commit check #2115

merged 1 commit into from
Nov 14, 2023

Conversation

happz
Copy link
Collaborator

@happz happz commented May 27, 2023

Another pair of eyes, pyright is a type check plus a bit more, and will inspect the code from slightyl different point of view. As a result, it will report issues mypy cannot spot, or cannot spot yet because the set of implemented checks is simply different.

The slow, gradual approach is the key here, like the one we know from mypy introduction, and slowly files and packages will get covered.

@happz happz added code | type annotations Related to type annotations and type cleanup test coverage Improvements or additions to test coverage of tmt itself labels May 27, 2023
@happz
Copy link
Collaborator Author

happz commented May 27, 2023

@martinhoyer would you have an experience with Pyright? I would like to add it as a complement to mypy, especially when it's able to spot some issues mypy does not report (yet?). However, the pre-commit integration is not as simple.

@martinhoyer
Copy link
Collaborator

@martinhoyer would you have an experience with Pyright?

Never used it myself, but read the discussion about pre-commit hook on pyright github. Looks like the wrapper you're using is the way for the foreseeable future. They mention it in their docs as well. (as I'm sure you're already know)
https://github.com/microsoft/pyright/blob/main/docs/ci-integration.md#running-pyright-as-a-pre-commit-hook

I wonder if we can tell pre-commit to re-use the mypy virtualenv, instead of creating new one with all those dependencies.

@happz
Copy link
Collaborator Author

happz commented Jun 1, 2023

@martinhoyer would you have an experience with Pyright?

Never used it myself, but read the discussion about pre-commit hook on pyright github. Looks like the wrapper you're using is the way for the foreseeable future. They mention it in their docs as well. (as I'm sure you're already know) https://github.com/microsoft/pyright/blob/main/docs/ci-integration.md#running-pyright-as-a-pre-commit-hook

Yep, I've read this one. The wrapper on its own would be fine, I dislike the duplication of requirements, but there seems to be no easy way around this issue :/

I wonder if we can tell pre-commit to re-use the mypy virtualenv, instead of creating new one with all those dependencies.

Maybe, I have no idea, but I will give it a try. On the other hand, mypy check is probably not installing any tmt dependencies, just Click and a pile of stubs. But yeah, we there would be some overlap, sharing might be nice.

pyproject.toml Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@happz happz added this to the 1.30 milestone Nov 5, 2023
@happz
Copy link
Collaborator Author

happz commented Nov 5, 2023

Ok, trying to get this one merged in its current state: duplication of requirements between pyproject.toml, mypy and pyright, documented, marked as something to fix later. I for one can live with this temporarily, the eventual goal is to have just one place where requirements live, maybe we could teach hatch & pre-commit to play nicely together.

WRT files to check, the check does nothing as of now. It's like the mypy introduction, does nothing, all files are ignored, and we'll be fixing files and modules as we go, making them pass both mypy and pyright checks.

@happz happz marked this pull request as ready for review November 5, 2023 16:34
@happz happz force-pushed the pre-commit-pyright branch 3 times, most recently from 9a77eb5 to 17e0fd9 Compare November 14, 2023 08:18
Copy link
Collaborator

@psss psss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just two typos and one question.

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
@psss psss self-assigned this Nov 14, 2023
@psss psss changed the title Add pyright as a pre-commit check Add pyright as a pre-commit check Nov 14, 2023
Another pair of eyes, pyright is a type check plus a bit more, and will
inspect the code from slightly different point of view. As a result, it
will report issues mypy cannot spot, or cannot spot *yet* because the
set of implemented checks is simply different.

The slow, gradual approach is the key here, like the one we know from
mypy introduction, and slowly files and packages will get covered.
@psss psss merged commit 3b58629 into main Nov 14, 2023
15 of 16 checks passed
@psss psss deleted the pre-commit-pyright branch November 14, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code | type annotations Related to type annotations and type cleanup test coverage Improvements or additions to test coverage of tmt itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants