File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1616#include " llvm/ADT/StringRef.h"
1717#include " llvm/ADT/Twine.h"
1818#include " llvm/Support/DataTypes.h"
19+ #include " llvm/Support/FormatVariadic.h"
1920#include " llvm/Support/raw_ostream.h"
2021
2122#include < string>
23+ #include < typeinfo>
2224#include < variant>
2325
2426template <>
@@ -344,7 +346,16 @@ class Sliceable {
344346
345347 // / Binds the indexing and length methods in the Python class.
346348 static void bind (nanobind::module_ &m) {
347- auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName)
349+ const std::type_info &elemTy = typeid (ElementTy);
350+ PyObject *elemTyInfo = nanobind::detail::nb_type_lookup (&elemTy);
351+ assert (elemTyInfo &&
352+ " expected nb_type_lookup to succeed for Sliceable elemTy" );
353+ nanobind::handle elemTyName = nanobind::detail::nb_type_name (elemTyInfo);
354+ std::string sig = std::string (" class " ) + Derived::pyClassName +
355+ " (collections.abc.Sequence[" +
356+ nanobind::cast<std::string>(elemTyName) + " ])" ;
357+ auto clazz = nanobind::class_<Derived>(m, Derived::pyClassName,
358+ nanobind::sig (sig.c_str ()))
348359 .def (" __add__" , &Sliceable::dunderAdd);
349360 Derived::bindDerived (clazz);
350361
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ def testTraverseOpRegionBlockIterators():
4343 )
4444 op = module .operation
4545 assert op .context is ctx
46+ # Note, __nb_signature__ stores the fully-qualified signature - the actual type stub emitted is
47+ # class RegionSequence(Sequence[Region])
48+ # CHECK: class RegionSequence(collections.abc.Sequence[mlir._mlir_libs._mlir.ir.Region])
49+ print (RegionSequence .__nb_signature__ )
4650 # Get the block using iterators off of the named collections.
4751 regions = list (op .regions [:])
4852 blocks = list (regions [0 ].blocks )
You can’t perform that action at this time.
0 commit comments