Skip to content

Conversation

@mrexodia
Copy link

@mrexodia mrexodia commented Dec 16, 2025

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 run and configured things in a way to be much more ergonomic for local development.

After running uv sync and selecting the virtual environment in VSCode the type hints work out of the box:

image

Similarly you can now do cmake -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON without nanobind installed globally on your system and clangd will function correctly:

image

You can also run type checking locally:

uvx ty check

Copilot AI review requested due to automatic review settings December 16, 2025 16:03
Copy link

Copilot AI left a 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_stub functionality
  • 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.

mrexodia added a commit to LLVMParty/llvm-nanobind that referenced this pull request Dec 16, 2025
mrexodia added a commit to LLVMParty/llvm-nanobind that referenced this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant