Skip to content

TYP: Run pyright_cov in CI, enforce minimum type completeness of 80% #29065

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

Closed
wants to merge 5 commits into from

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented May 27, 2025

As discussed on Slack: https://numpy-team.slack.com/archives/C01BZCJ6NJ0/p1748280881632649

The idea is to prevent Pyright's type compeleteness from suddenly regressing - if it did, it would indicate an incorrect type (as was fixed in #28908)

Copy link
Member

@jorenham jorenham left a comment

Choose a reason for hiding this comment

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

Maybe we already use basedpyright for this? It has some additional inference and narrowing features that might be helpful here, e.g.
https://docs.basedpyright.com/latest/benefits-over-pyright/improved-generic-narrowing/. And if I understand correctly, then its baseline feature could be used as an alternative to --exclude-like.

It might be possible to replace this with `basedpyright`
https://github.com/DetachHead/basedpyright/issues/125 in the future.
"""
from __future__ import annotations
Copy link
Member

Choose a reason for hiding this comment

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

is this needed?

@jorenham
Copy link
Member

jorenham commented May 27, 2025

Maybe it would be nice if we could have the CI complain if the % drops as a consequence of the changes? Although I'm not sure what the best way to implement something like that 🤔.

@@ -72,3 +72,8 @@ jobs:
- name: Run Mypy
run: |
spin mypy
- name: Check Pyright's type compelteness is above 80%
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- name: Check Pyright's type compelteness is above 80%
- name: Check Pyright's type completeness is above 80%

@MarcoGorelli
Copy link
Member Author

Maybe we already use basedpyright for this? It has some additional inference and narrowing features that might be helpful here, e.g. https://docs.basedpyright.com/latest/benefits-over-pyright/improved-generic-narrowing/. And if I understand correctly, then its baseline feature could be used as an alternative to --exclude-like.

sure but wouldn't we need DetachHead/basedpyright#125 to be closed first?

@jorenham
Copy link
Member

jorenham commented May 27, 2025

Maybe we already use basedpyright for this? It has some additional inference and narrowing features that might be helpful here, e.g. docs.basedpyright.com/latest/benefits-over-pyright/improved-generic-narrowing. And if I understand correctly, then its baseline feature could be used as an alternative to --exclude-like.

sure but wouldn't we need DetachHead/basedpyright#125 to be closed first?

No, --verifytypes already works. The idea behind DetachHead/basedpyright#125 is to make it possible for --verifytypes to be enabled as a diagnostic rule, so we can use e.g. # pyright: ignore[reportVerifyTypes] or pyright: reportVerifyTypes=false to ignore what we need to ignore. That way, we could configure it to only enable the reportVerifyTypes rule, and we just basedpyright numpy (without --verifytypes), which will then fail if any new errors pop up. We could use the baseline feature to generate all of the initial ignore's, so no need for manual labor.

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Jun 10, 2025

thanks - i've tried running

spin run python -m  basedpyright  --verifytypes numpy --writebaseline

but I'm not getting any outputs written anywhere

the docs mention ./.basedpyright/baseline.json, but I don't see it

(numpy-dev) marcogorelli@DESKTOP-U8OKFP3:~/numpy-dev$ ls ./.basedpyright
ls: cannot access './.basedpyright': No such file or directory

can you see what i might be doing wrong?


sorry for the delay, had pycon italy + some PTO

@jorenham
Copy link
Member

Hmm yea --writebaseline doesn't seem to work when combined with --verifytypes.
Is there something we're doing wrong here, @DetachHead ?

@jorenham
Copy link
Member

without --verifytypes it seems to work, and it produces a .basedpyright/baseline.json of 30.4 MB (!), for the 11,719 errors and 117,354 warnings. But that also includes all .py sources and typing tests, so I added this to the pyproject.toml

[tool.basedpyright]
include = ["numpy"]
ignore = ["**/*.py", "**/tests/*"]
exclude = [".spin", "benchmarks", "build", "build-install", "doc", "tools"]
stubPath = "."
pythonPlatform = "All"

typeCheckingMode = "strict"
disableBytesTypePromotions = true
enableReachabilityAnalysis = false
enableTypeIgnoreComments = false
reportIgnoreCommentWithoutRule = true
reportPropertyTypeMismatch = false
reportPrivateUsage = false
reportShadowedImports = false
reportUnnecessaryTypeIgnoreComment = true

and ran it again with basedpyright --writebaseline to get a ~400 kB baseline.json of 1663 errors.

However, if I now run basedpyright --verifytypes numpy (which requires numpy to be installed, but not in editable mode), I see the exact same 22.6% "type completeness score" as I saw without the baseline.json. So I suppose that'll have to wait until DetachHead/basedpyright#125 then.

@MarcoGorelli
Copy link
Member Author

sure - i'll close this then in favour of a basedpyright solution when it's available

@DetachHead
Copy link

--verifytypes is a completely different thing to the normal type checker for some reason, so it probably doesn't work with baseline unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants