Skip to content

Update nanobind to 2.15.0 - #4337

Open
XXXXRT666 wants to merge 5 commits into
ml-explore:mainfrom
XXXXRT666:nanobind-2.15-support
Open

Update nanobind to 2.15.0#4337
XXXXRT666 wants to merge 5 commits into
ml-explore:mainfrom
XXXXRT666:nanobind-2.15-support

Conversation

@XXXXRT666

Copy link
Copy Markdown
Contributor

Proposed changes

Update nanobind from 2.13.0 to 2.15.0 for the MLX Python bindings and extension examples.

This change also:

  • adds coverage for the updated nanobind integer conversion semantics, accepting objects that implement __index__ while rejecting floating-point and string inputs
  • updates the stub generation patterns for nanobind 2.15, including generated imports, aliases, comparison return types, and context manager signatures
  • adds non-blocking Ruff and ty checks for generated mlx.core stubs in the Linux CPU CI job

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@XXXXRT666

Copy link
Copy Markdown
Contributor Author

With the updated stubs, ty check completes without warnings, and array comparisons are correctly inferred to return an mx.array:

a = mx.array(...)
b = a == a  # correctly inferred as mx.array rather than bool | mx.array

- name: Check generated Python stubs with ty
if: matrix.os == 'Linux' && matrix.arch == 'x86_64' && matrix.toolkit == 'cpu'
continue-on-error: true
run: uvx ty check python/mlx/core

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv check seems to be ty now?

Since type checking passes now I would like to make it mandatory, I don't care about making every type checker happy and we can drop Ruff.

@XXXXRT666 XXXXRT666 Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv check relies on the project metadata in pyproject.toml, it cannot be scoped to just the generated stubs I think. Running it at the repository root currently reports hundreds of diagnostics. A full Ruff check on the generated stubs also reports 150 errors

I dropped the Ruff step and made the targeted uvx ty check python/mlx/core check mandatory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks for fixing the type errors!

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.

2 participants