[Mlir-commits] [mlir] [MLIR][Python] make Sliceable inherit from Sequence (PR #170551)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Fri Dec 5 00:26:19 PST 2025


================
@@ -344,7 +345,16 @@ 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 for Sliceable elemTy");
+    nanobind::handle elemTyName = nanobind::detail::nb_type_name(elemTyInfo);
+    std::string sig = std::string("class ") + Derived::pyClassName +
+                      "(collections.abc.Sequence[" +
+                      nanobind::cast<std::string>(elemTyName) + "])";
----------------
ftynse wrote:

Don't we have `ElementTy::pyClassName` similarly to `Derived::pyClassName`? Maybe not everywhere, but something to consider. This is probably the first time I see `typeid` being used in non-toy code so I don't know how well it works across platforms.

https://github.com/llvm/llvm-project/pull/170551


More information about the Mlir-commits mailing list