-
Notifications
You must be signed in to change notification settings - Fork 55
Add typing support and switch to uv #73
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
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.
Pull request overview
This PR modernizes the nanobind example project by adding comprehensive type checking support and migrating to uv as the development tool. The changes include generating type stubs for C++ extension modules, updating Python version requirements, and adding CI workflows to verify type checking functionality.
Key changes:
- Migrated from pip-based development to uv with automatic rebuild on source changes
- Added type stub generation using nanobind's
nanobind_add_stubfunctionality - Implemented type checking CI workflow with ty, pyright, and mypy verification
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| typecheck_smoke.py | New smoke test file with intentional type errors to verify type stubs are working |
| tests/test_basic.py | Minor formatting change (added blank line) |
| src/nanobind_example_ext.cpp | Refactored lambda to named function and added docstring for better type stub generation |
| src/nanobind_example/init.py | Changed to absolute imports for proper type checking support |
| pyproject.toml | Updated dependencies, added type checker configurations, and uv tool settings |
| README.md | Added comprehensive development documentation for uv, type checking, and project structure |
| CMakeLists.txt | Added type stub generation, improved build configuration, and nanobind fetching for development |
| .python-version | Added Python version file for uv |
| .github/workflows/pip.yml | Added type checking job with verification tests |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reference: wjakob/nanobind_example#73
Reference: wjakob/nanobind_example#73
I noticed that this official example does not support generating type stubs and (IDE) type checking correctly. I switched to uv, which makes building the extension transparent on
uv runand configured things in a way to be much more ergonomic for local development.After running
uv syncand selecting the virtual environment in VSCode the type hints work out of the box:Similarly you can now do
cmake -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ONwithoutnanobindinstalled globally on your system and clangd will function correctly:You can also run type checking locally: