-
Notifications
You must be signed in to change notification settings - Fork 1.4k
type stubs for some third-party libraries #3443
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
base: main
Are you sure you want to change the base?
Conversation
DouweM
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lars20070 Thanks Lars, this is great.
| "stubs/**/*.pyi" = ["F401", "PYI044", "PYI035", "ANN401"] | ||
|
|
||
| [tool.pyright] | ||
| stubPath = "stubs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call it type_stubs or something like that to make it more clear what it's about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no PEP rule demanding a ./stubs folder. But PEP 484 is linking to typeshed which is using ./stubs. So are mypy and the Microsoft's stubs collection. On the other hand, Pyright goes with ./typings.
The name ./stubs is not required, but a convention. I have explained the folder in the corresponding README. It's like renaming the src folder to source. Yes, possible. But why do it?
| local_dir: str | PathLike[str] | None = None, | ||
| local_dir_use_symlinks: bool | Literal['auto'] = 'auto', | ||
| cache_dir: str | PathLike[str] | None = None, | ||
| **kwargs: Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will inevitably get outdated -- could you add some docs (can just be a readme in this dir) on how you generated them, how we can validate they're still valid, and how to regenerate/update them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DouweM I have added a README to the ./stubs folder.
Either update any API changes manually from the source code, or give Copilot access to a Context7 MCP server and let the coding agent do the updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, the rebase introduced new outlines code. I have added the necessary stubs.
| .PHONY: typecheck-mypy | ||
| typecheck-mypy: | ||
| uv run mypy | ||
| uv run mypy stubs/ --strict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DouweM I have added validation of the stubs here.
Problem
The codebase previously relied on
# type: ignoreand# pyright: ignorecomments to suppress type errors from third-party libraries lacking type hints (llama_cpp,mlx,mlx_lm,outlines,transformers, andvllm).make typecheckfailed due to missing type information frommlxandvllm. Both dependencies are absent in the Linux dev container.Solution
This PR introduces type stub files
.pyifor these libraries. Type stubs provide type information to static type checkers without modifying the runtime behavior.SamplingParamsfromvllm.uv run stubgentarget inMakefile. But this generates all stubs and not merely the ones used in the codebase. More thoughts here.make typechecknow passes successfully in the Linux dev containerAdded
stubs/directory containing type stub files forllama_cpp,mlx,mlx_lm,outlines,transformersandvllm.pyproject.tomlto configure stub search paths forpyrightandmypyChanged
outlines-mlxlmhas been updated in bothpyproject.tomlfiles.uv.lockfile has been updated to reflect these dependency changes.Removed
# pyright: ignoreand# type: ignorecomments fromoutlines.pyandtest_outlines.py.