Repository navigation
Description
pyright is a static type checker written by Microsoft (and they have a really good verification team)
it is written in typescript but there is a python wrapper and a pre-commit hook.
There are certain cases that mypy does not check strictly while pyright does.
For example, the following code passes mypy while not in pyright
from typing_extensions import TypeVar
T = TypeVar("T")
S = TypeVar("S", default=int)
U = TypeVar("U")
def fn(x: T, y: S, z: U):
pass
(mellea) [masataro mellea]$ pyright test.py
/home/masataro/repos/LLM/mellea/test.py
/home/masataro/repos/LLM/mellea/test.py:12:5 - error: "U" cannot appear after "S" in type parameter list because it has no default type (reportGeneralTypeIssues)
/home/masataro/repos/LLM/mellea/test.py:12:11 - warning: TypeVar "T" appears only once in generic function signature
Use "object" instead (reportInvalidTypeVarUse)
/home/masataro/repos/LLM/mellea/test.py:12:22 - warning: TypeVar "U" appears only once in generic function signature
Use "object" instead (reportInvalidTypeVarUse)
1 error, 2 warnings, 0 informations
(mellea) [masataro mellea]$ mypy test.py
Success: no issues found in 1 source file
Thsi is because it makes sure that no type parameter with a default is followed by a type parameter without a default.
Type variables are applied to the defined class in the order in which they first appear in any generic base classes, thus
fn is instantiated as fn[T, S, U] where U violates this rule.
This was originally specified in PEP 696 (Type Defaults for Type Parameters) and
is now part of official spec https://typing.python.org/en/latest/spec/generics.html#type-parameter-defaults .
The annoying thing is that VSCode suggests users to enable pylance/pyright , and reports a bunch of similar errors to the user that are not detected by mypy.
Activity
[-]Replace mypy check with pyright check[/-][+]Add pyright check[/+]psschwei commentedon Feb 11, 2026
Do we need to keep both? Or could we remove mypy in favor of pyright?
guicho271828 commentedon Feb 12, 2026
Now to think of it ....
Reading a discussion like this, I feel pyright will further slow down the local development.
So far I am already heavily annoyed by the fact that each time I make a commit, even a temporary commit, it forces me to type check and lint everything. Basically, the current set up in this repo prohibits a typical git workflow where I make multiple branches to experiment, make temporary commits, push it to remote so that I can work from multiple devices (from laptop, compute server login node, and so on), make sure they work, polish it by rewriting/squashing them, and submit a PR for merging.
It makes sense to protect the integrity of the main branch with mypy/pyright and therefore to check every PR with mypy, linter, and so on. It does not make sense to disallow making a temporary commit. (In addition, I can't even make a commit in magit because magit calls git outside the conda environment, which does not have uv and mypy. Every time I have to go back to the terminal to make a commit only in this project).
psschwei commentedon Feb 12, 2026
🎉
I think this might be worth revisiting (I too feel this pain). Maybe we should open a discussion?
planetf1 commentedon Mar 17, 2026
It's possible to bypass commits with a
--no-verify. I do use this sometimes - especially when experimenting/early stage or just to keep things 'safe' .But in general having a pre-commit I feel is good - it can save the time from waiting to see a PR fail CI, and when coding with AI agents this forced-check (without override) encourages them to correct, regardless of any specific guidance.
Rigour/tool quality is related -- two newer projects are Pyrefly (meta) and ty (astral) - but with different coverage/maturity. I do find mypy frequently painful as a specific checker - it's slow, seems to often trip up/need cache resetting
planetf1 commentedon Mar 17, 2026
ty:
psschwei commentedon Mar 17, 2026
My personal preference is to not block committing and let the CI catch failures (if folks are pushing directly to main then it's a different story). But it's not super important, whatever most folks want is fine.
planetf1 commentedon Mar 26, 2026
I did a comparison of pyright, ty, mypy- here's a summarised report after getting tests run across all of these, with some analysis and tightning of the checks:
Type Checker Comparison: What Each Tool Finds in
mellea/CoreRaw Numbers
# type: ignore¹
check_untyped_defs = true+warn_unused_ignores = trueFalse Positive Patterns (Same Root Cause Across Tools)
MelleaBasePayloadattrs missingTYPE_CHECKINGbase class in plugin systemmodel_fields_set/model_extratry/exceptimport → possibly unboundtryblock, guarded by_HAS_PLUGIN_FRAMEWORKat runtimeCallable.__name__(...) -> Unknown, no__name__on that protocol~AlwaysFalsyafter guardBoth tools trip on the same optional-dependency patterns. Neither is clean on this codebase without suppression.
Unique Findings — What Each Tool Catches Alone
# type: ignorecomments (121-215)invalid-argument-type(24 in core)invalid-return-type(7 in core)invalid-assignment(7 in core)UnboundLocalError)reportRedeclaration(2)² Only with
check_untyped_defs = trueThe 4 Bugs Only pyright Finds
dict_idanddoc_rolesused inexcept/elseblocks after assignment intry— if thetryfails before the assignment, these are unbound at runtime. Neither mypy nor ty detects this. Files:mellea/formatters/granite/granite3/output.py:266mellea/formatters/granite/granite3/granite32/output.py:481mellea/formatters/granite/granite3/granite33/output.py:381mellea/formatters/granite/intrinsics/input.py:144These should be fixed regardless of which tool we adopt.
Recommendation
Don't pick one tool. Use two, for different jobs.
check_untyped_defs = trueandwarn_unused_ignores = truegoes from 1 → ~267 findings with zero false positives. Stable, no new infra.pyproject.toml. Suppress the 37 false positives via overrides.PossiblyUnboundandRedeclarationbugs that neither mypy nor ty finds. Not worth adding to CI (Node.js dep, 41% noise rate).Immediate Actions
pyproject.toml:So in summary mypy does seem to remain probably the best CI checker -- but we're missing things and tightning that up would be beneficial.
But ty can be useful as a dev tool and it may be friendlier to use in pre-commit -- if we continue to have anything there. If we do want that, this was the config I ended up with:
That in itself shows there are some very specific pain points in specific files
Just maybe, and until ty is more mature, sticking with mypy but tightning up the rules & cleaning up those missing type issues is the most pragmatic step, rather than going to ty or pyright (which is painful due to nodejs)
psschwei commentedon May 12, 2026
we're going to stay with status quo for now