← Back to blog

My First Contributions to nanobind

On September 28, two of my pull requests were merged into nanobind. They were my first contributions to the project, and both came from edge cases where Python behavior did not quite match what the C++ binding was meant to express.

Enum aliases should be aliases

In Python, two names for the same enum value should refer to the same enum member. I found that duplicate C++ enum values could instead produce separate Python objects. The fix was to look up an existing member before creating a new one, so an alias reuses the original object. The regression coverage checks identity as well as canonical names, iteration, and generated stubs.

PR #1441: Fix enum alias identity

Keeping a custom constructor signature intact

The second issue involved nb::new_ and a custom nb::sig. The signature was also being passed to a generated no-op __init__, where the method flags did not match and importing the extension could abort. The change filters it from that binding while keeping it on __new__. Tests cover overloads, displayed signatures, construction, subclassing, and allocation for unpickling.

PR #1443: Fix custom signatures on nb::new_

These fixes were small in scope, but they gave me a useful first look at contributing to a mature C++ library: trace the surprising behavior to the binding path, make the change narrowly, and add a regression test that describes what users should see. I’m glad to have my first nanobind contributions merged.

— Jad