-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Demo: Testing pybind11-stubgen + mypy #5678
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: master
Are you sure you want to change the base?
Conversation
Some errors I see so far:
|
The new test dependencies seem "small/lightweight" and "super lightweight":
I think you're going in a great direction.
That sounds like a great idea, as long as you build in an easy way to turn that off during development iterations. I'd only want to turn that on again while I clean up for the next If you do that, I'd say forget the tests under #4888 (those came mostly from mypy). I believe they'll be 100% redundant.
I'd look at that is the top priority. — I don't know a lot about typing, but last time I quizzed ChatGPT about it (a few months ago), it told me |
If you haven't started using $ uv venv
Using CPython 3.13.3 interpreter at: /usr/local/opt/[email protected]/bin/python3.13
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate.fish
________________________________________________________
Executed in 28.56 millis fish external
usr time 12.44 millis 0.25 millis 12.19 millis
sys time 13.04 millis 1.91 millis 11.13 millis
$ time uv pip install mypy
Resolved 3 packages in 3ms
Installed 3 packages in 50ms
+ mypy==1.15.0
+ mypy-extensions==1.1.0
+ typing-extensions==4.13.2
________________________________________________________
Executed in 81.80 millis fish external
usr time 18.27 millis 0.29 millis 17.98 millis
sys time 54.27 millis 3.55 millis 50.73 millis I think ty and pyrefly, the two new Python type checkers in Rust, are likely to have a big impact in the future, but for now, most projects work on passing mypy, and the existing type checkers like pylance know that and try to be compatible. I don't think I use anything other than mypy in CI on all my projects, though I use pyright locally in VSCode and via LSP in Vim. The bug in Python 3.14.0b1 that we've reported also affects mypy, and it's been marked as a release blocker. So mypy will likely work better in beta 2. |
Description
This PR shows how pybind11-stubgen and mypy could be used in pytest to check for correct type hints.
It stems from the discussion at #5663.
This is just a quick demo with one positive and one negative test.
Sources for calling pybind11-stubgen and mypy from Python:
Add args to main sizmailov/pybind11-stubgen#252
(thx @gentlegiantJGC for this 👍)
TODOs:
Annotated[Any, pybind11.CppType("cpp_namespace::UserType")]
#4888📚 Documentation preview 📚: https://pybind11--5678.org.readthedocs.build/