benchmark/bindings/python/google_benchmark
Peter Hawkins 64b5d8cd11
Update benchmark Python bindings for nanobind 2.0, and update to nanobind 2.0. (#1817)
Incorporates the nanobind_bazel change from https://github.com/google/benchmark/pull/1795.

nanobind 2.0 reworked the nanobind::enum_ class so it uses a real Python enum or intenum rather than its previous hand-rolled implementation.
https://nanobind.readthedocs.io/en/latest/changelog.html#version-2-0-0-may-23-2024

As a consequence of that change, nanobind now checks when casting an integer to a enum value that the integer corresponds to a valid enum. Counter::Flags is a bitmask, and many combinations are not valid enum members.

This change:
a) sets nb::is_arithmetic(), which means Counter::Flags becomes an IntEnum that can be freely cast to an integer.
b) defines the | operator for flags to return an integer, not an enum, avoiding the error.
c) changes Counter's constructor to accept an int, not a Counter::Flags enum. Since Counter::Flags is an IntEnum now, it can be freely coerced to an int.

If https://github.com/wjakob/nanobind/pull/599 is merged into nanobind, then we can perhaps use a flag enum here instead.
2024-07-18 16:54:02 +01:00
..
BUILD Add Python bindings build using bzlmod (#1764) 2024-03-07 12:28:55 +00:00
__init__.py Add Python bindings build using bzlmod (#1764) 2024-03-07 12:28:55 +00:00
benchmark.cc Update benchmark Python bindings for nanobind 2.0, and update to nanobind 2.0. (#1817) 2024-07-18 16:54:02 +01:00
example.py Add pre-commit config and GitHub Actions job (#1688) 2023-10-30 15:35:37 +00:00
version.py Add `setuptools_scm` for dynamic zero-config Python versioning (#1690) 2023-11-01 09:48:01 +00:00