[Mlir-commits] [mlir] [MLIR][Python] make Sliceable inherit from Sequence (PR #170551)
Maksim Levental
llvmlistbot at llvm.org
Wed Dec 3 12:26:41 PST 2025
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/170551
>From d865b48b097449032c0fb2047cab9cfde0677994 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 3 Dec 2025 12:22:06 -0800
Subject: [PATCH] [MLIR][Python] make Sliceable inherit from Sequence
---
mlir/lib/Bindings/Python/NanobindUtils.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Bindings/Python/NanobindUtils.h b/mlir/lib/Bindings/Python/NanobindUtils.h
index 658e8ad5330ef..9519a643adfcf 100644
--- a/mlir/lib/Bindings/Python/NanobindUtils.h
+++ b/mlir/lib/Bindings/Python/NanobindUtils.h
@@ -19,6 +19,7 @@
#include "llvm/Support/raw_ostream.h"
#include <string>
+#include <typeinfo>
#include <variant>
template <>
@@ -344,7 +345,17 @@ class Sliceable {
/// Binds the indexing and length methods in the Python class.
static void bind(nanobind::module_ &m) {
- auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName)
+ const std::type_info &elemTy = typeid(ElementTy);
+ PyObject *elemTyInfo = nanobind::detail::nb_type_lookup(&elemTy);
+ assert(elemTyInfo && "expected nb_type_lookup to succeed");
+ nanobind::handle elemTyName = nanobind::detail::nb_type_name(elemTyInfo);
+ std::string sig = "class ";
+ sig += Derived::pyClassName;
+ sig += "(collections.abc.Sequence[";
+ sig += nanobind::cast<std::string>(elemTyName);
+ sig += "])";
+ auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName,
+ nanobind::sig(sig.c_str()))
.def("__add__", &Sliceable::dunderAdd);
Derived::bindDerived(clazz);
More information about the Mlir-commits
mailing list