-
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?
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.
It's just a bit unclear to people new to the repo/Python typing, who'll have no idea what "stubs" means and what the dir could contain. Those examples you mentioned are dedicated to stubs, so it makes sense to use that name, but I'd find it more convincing if there's an other non-typing-specific Python package that has a top-level stubs dir. I like typings or type_stubs better
| maintained. When a dependency's API changes, both the codebase and the stubs | ||
| need to be updated. There are two ways to update the stubs: | ||
|
|
||
| (1) **Manual update:** Check the dependency's source code and copy the type |
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.
Let's format this like a Markdown list with 1.
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.