MNT Use pyrefly instead of mypy for type-checking - #34527
Conversation
cb2cb90 to
f9bd7ff
Compare
| [tool.pyrefly.errors] | ||
| bad-override = false |
There was a problem hiding this comment.
there's hundreds of errors from bad-override due to incompatible constructors
mypy (with the current configuration) doesn't flag these
so, for now, i'd suggest not checking this with pyrefly either
| # as xfail. | ||
| status = "xfail" | ||
| else: | ||
| status = "failed" |
There was a problem hiding this comment.
i'm moving this up from L948 so that check_result can be instantiated with all fields present
| [tool.pyrefly] | ||
| project-includes = ["sklearn"] | ||
| project-excludes = ["**/sklearn/externals*"] | ||
| preset = "legacy" |
There was a problem hiding this comment.
this is similar to mypy's current level of strictness. if you want to opt in to a higher level of strictness, I'd suggest leaving that to a separate PR
|
I think there is a |
| # FutureWarnings | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", FutureWarning) | ||
| # mypy error: Module has no attribute "__path__" |
There was a problem hiding this comment.
__path__ doesn't appear here anyway, not sure what this comment was doing here 😄
|
thanks for your review! have addressed tagging @AnneBeyer and @adrinjalali as they were involved with #32737 |
adrinjalali
left a comment
There was a problem hiding this comment.
This is actually a nice improvement to what we have, I like it.
@AnneBeyer wanna have a look?
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| # typing_extensions is available when mypy is installed |
There was a problem hiding this comment.
still need some sort of a comment here
There was a problem hiding this comment.
sure thanks - i've rephrased a bit as it's not a dependency of pyrefly (like it is of mypy), but pyrefly can understand its symbols
@adrinjalali so that we are on a similar page and remember what we were hoping for if we ever merge this PR: what do you like and what is the improvement exactly? Here are a few guesses, there could be others:
My personal feeling is that broadly speaking there is not a strong interest about typing in scikit-learn and my guess is that it is unlikely that we invest time into adding more typing in the medium-term. Switching to a different typechecker (that feels like maybe a bit less standard) feels more like a risk, and the benefits are not 100% clear to me. Having said this, I wish we were sometimes more adventurous in scikit-learn where possible and switching a developer tool doesn't affect users's experience too much, so I am open to change my mind if there are good arguments 🤷. |
|
@lesteve in my experience, the default behaviour of There is an option to change preset to a stricter one, which will make contributors fight the typecheker for sure. In general, default preset shouldn't make life harder for anybody and will speed up the check. |
|
I'd be interested in a switch to a type checker that is faster than mypy. I don't really care for static typing in scikit-learn, so reducing the amount of time spent staring at the pre-commit messages waiting for mypy to "do its thing, what ever that might be" is something I'd be happy to support. At the same time, because I don't find static typing to be all that useful I am interested in keeping type checking related churn down. This means that if we switch we should switch to a type checker that has some history in terms of being well maintained, widely used and still here in a few years time. From my little investigation about type checkers I think pyrefly ticks those boxes, maybe except for the last one?? |
AnneBeyer
left a comment
There was a problem hiding this comment.
Thank you for taking this on @MarcoGorelli!
From what I understand, it doesn't change the behavior (still ignores the things we want to ignore) while cleaning up the code a bit and taking less time, so I would be happy to see this change as well.
Since we have the linting lock files and a running version in this PR, we can always pin it if future updates would create a maintenance overhead on our end.
One thing I noticed when checking out this PR and testing it by committing something (without changing anything in the installation of pre-commit): I didn't have to install pyrefly myself. The first commit took a bit longer, and from what I understand, it was installed automatically in ~/.cache/pre-commit/..., so we might not even have to add it to the installation instructions? In any case, it looks like it will not even disrupt the contributor experience (except for an unexpected delay on the first commit after merging main).
|
thanks! for pre-commit, in general, it doesn't require you to install anything, it handles it all for you so:
same for all the other tools, this isn't unique to pyrefly |
|
Ah, that makes sense. Thank you for the clarification! If I understand correctly, this means that, since we instruct contributors to use pre-commit, we could actually remove |
|
@lorentzenchr feel free to merge it and I guess you will be the main person to deal with the consequences if any 😜 🤞. It seems like the consensus is:
|
|
Something that we need to look out for is that existing PRs that do not merge |
|
Good point, I am not 100% sure what will happen ... as maintainer, it's probably safer to click on "Update branch" and then set automerge rather than merging an not super recent PR directly? I guess that was implicitly included in "deal with the consequences if any" 😉. |
|
For completeness and better awareness, if you push a commit into a branch where The error is something like this: I saw this in #34676 (comment). |
|
Annoyingly (or at least semi-annoyingly) there is no bot linting comment when linting fails early, I opened #34719 about it. |
Reference Issues/PRs
closes #34502
I've kept
.mypy_cacheexcluded in.gitignoreand some other places because contributors probably still have that folder (unchecked) locally, so this will avoid unexpected issue for themWhat does this implement/fix? Explain your changes.
First time contributor introduction
AI usage disclosure
I used AI assistance for:
Any other comments?