[Mlir-commits] [mlir] [MLIR][Python] Register Containers as Sequences for `match` compatibility (PR #174091)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 31 06:28:51 PST 2025


================
@@ -4951,6 +4951,22 @@ void mlir::python::populateIRCore(nb::module_ &m) {
   PyRegionIterator::bind(m);
   PyRegionList::bind(m);
 
+  // Register containers as Sequences, so they can be used with `match`.
+  nanobind::object scope = m.attr("__dict__");
+  nanobind::exec("from collections.abc import Sequence, Mapping\n"
+                 "Sequence.register(BlockArgumentList)\n"
+                 "Sequence.register(BlockList)\n"
+                 "Sequence.register(BlockSuccessors)\n"
+                 "Sequence.register(BlockPredecessors)\n"
+                 "Sequence.register(OperationList)\n"
+                 "Sequence.register(OpOperandList)\n"
+                 "Sequence.register(OpResultList)\n"
+                 "Sequence.register(OpSuccessors)\n"
+                 "Sequence.register(RegionSequence)\n"
+                 "OpAttributeMap.get = Mapping.get\n"
----------------
MaPePeR wrote:

You mean not define the `OpAttributeMap` as a `Mapping` for now?

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


More information about the Mlir-commits mailing list