Skip to content

Commit e2291a9

Browse files
committed
[MLIR][Python] make Sliceable inherit from Sequence
1 parent c379f7c commit e2291a9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mlir/lib/Bindings/Python/NanobindUtils.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Support/raw_ostream.h"
2020

2121
#include <string>
22+
#include <typeinfo>
2223
#include <variant>
2324

2425
template <>
@@ -344,7 +345,16 @@ class Sliceable {
344345

345346
/// Binds the indexing and length methods in the Python class.
346347
static void bind(nanobind::module_ &m) {
347-
auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName)
348+
const std::type_info &elemTy = typeid(ElementTy);
349+
PyObject *elemTyInfo = nanobind::detail::nb_type_lookup(&elemTy);
350+
nanobind::handle elemTyName = nanobind::detail::nb_type_name(elemTyInfo);
351+
std::string sig = "class ";
352+
sig += Derived::pyClassName;
353+
sig += "(collections.abc.Sequence[";
354+
sig += nanobind::cast<std::string>(elemTyName);
355+
sig += "])";
356+
auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName,
357+
nanobind::sig(sig.c_str()))
348358
.def("__add__", &Sliceable::dunderAdd);
349359
Derived::bindDerived(clazz);
350360

0 commit comments

Comments
 (0)