[Mlir-commits] [mlir] 0d3f7ae - [mlir][python] Make Python bindings compatible with Nanobind v3.0.0. (#218562)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 25 07:25:59 PDT 2026
Author: Peter Hawkins
Date: 2026-08-25T07:25:54-07:00
New Revision: 0d3f7ae1e926261d532e0cfc92799673ed49489b
URL: https://github.com/llvm/llvm-project/commit/0d3f7ae1e926261d532e0cfc92799673ed49489b
DIFF: https://github.com/llvm/llvm-project/commit/0d3f7ae1e926261d532e0cfc92799673ed49489b.diff
LOG: [mlir][python] Make Python bindings compatible with Nanobind v3.0.0. (#218562)
Nanobind v3.0.0 has several breaking changes, notably changes to how
iterators work and removal of several nanobind::detail APIs.
https://nanobind.readthedocs.io/en/latest/changelog.html#version-3-0-0-aug-22-2026
Assisted-by: Gemini
Added:
Modified:
mlir/include/mlir/Bindings/Python/NanobindUtils.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/Bindings/Python/NanobindUtils.h b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
index ea43356d2cf54..4f3dd7446b588 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindUtils.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindUtils.h
@@ -24,6 +24,16 @@
#include <typeinfo>
#include <variant>
+#if NB_VERSION_MAJOR >= 3
+template <bool IsTuple>
+struct std::iterator_traits<nanobind::detail::seq_iterator<IsTuple>> {
+ using value_type = nanobind::handle;
+ using reference = const value_type;
+ using pointer = void;
+ using
diff erence_type = std::ptr
diff _t;
+ using iterator_category = std::forward_iterator_tag;
+};
+#else
template <>
struct std::iterator_traits<nanobind::detail::fast_iterator> {
using value_type = nanobind::handle;
@@ -32,6 +42,7 @@ struct std::iterator_traits<nanobind::detail::fast_iterator> {
using
diff erence_type = std::ptr
diff _t;
using iterator_category = std::forward_iterator_tag;
};
+#endif
namespace mlir {
namespace python {
@@ -475,14 +486,12 @@ class Sliceable {
return nullptr;
})},
{0, nullptr}};
- const std::type_info &elemTy = typeid(ElementTy);
- PyObject *elemTyInfo = nanobind::detail::nb_type_lookup(&elemTy);
- assert(elemTyInfo &&
- "expected nb_type_lookup to succeed for Sliceable elemTy");
- nanobind::handle elemTyName = nanobind::detail::nb_type_name(elemTyInfo);
+ nanobind::handle elemTyInfo = nanobind::type<ElementTy>();
+ assert(elemTyInfo.is_valid() &&
+ "expected nanobind::type to succeed for Sliceable elemTy");
+ nanobind::str elemTyName = nanobind::type_name(elemTyInfo);
std::string sig = std::string("class ") + Derived::pyClassName +
- "(collections.abc.Sequence[" +
- nanobind::cast<std::string>(elemTyName) + "]";
+ "(collections.abc.Sequence[" + elemTyName.c_str() + "]";
if constexpr (!Derived::typeParams.empty()) {
sig += ", typing.Generic[";
for (size_t i = 0; i < Derived::typeParams.size(); ++i) {
More information about the Mlir-commits
mailing list