Skip to content

Use new py::make_scalar and dtype.normalized_num#3816

Merged
jl-wynen merged 2 commits intomainfrom
new-pybind11-3-features
Jan 22, 2026
Merged

Use new py::make_scalar and dtype.normalized_num#3816
jl-wynen merged 2 commits intomainfrom
new-pybind11-3-features

Conversation

@jl-wynen
Copy link
Copy Markdown
Member

I went through the new features in Pybind11 and found two that are useful to us. Please look at the commits separately! Consider this PR more of a proposal, not a request. This only improves readability in code we never actually look at.

py::make_scalar almost implements what we did ourselves in make_scalar but only supports numeric types (for now). There is a breaking change here: sc.scalar(False).value is currently a bool. With this change, this turns into a np.bool_. I think this makes sense for consistency with NumPy. It should not break anything in practice unless someone uses code like var.value is True, which is bad code anyway.

normalized_num and num_of make it more straight forward to check dtypes. But they don't support all types we need as far as I can tell. So the proposed scipp_dtype is simpler than before (no nesting) but not as clean as I had hoped.

@jl-wynen jl-wynen force-pushed the new-pybind11-3-features branch from a046a4f to 288b9f8 Compare January 21, 2026 08:43
@jl-wynen jl-wynen enabled auto-merge January 21, 2026 08:43
@jl-wynen jl-wynen force-pushed the new-pybind11-3-features branch 2 times, most recently from 4b08dc0 to bf5214a Compare January 21, 2026 13:52
@jl-wynen jl-wynen force-pushed the new-pybind11-3-features branch from bf5214a to bbb8c25 Compare January 22, 2026 07:41
@jl-wynen jl-wynen merged commit e6e2bcd into main Jan 22, 2026
4 checks passed
@jl-wynen jl-wynen deleted the new-pybind11-3-features branch January 22, 2026 07:52
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