[Mlir-commits] [mlir] [MLIR][Python] Support `has_trait` for operations (PR #188492)

Rolf Morel llvmlistbot at llvm.org
Wed Mar 25 12:47:00 PDT 2026


================
@@ -3963,7 +3964,13 @@ void populateIRCore(nb::module_ &m) {
              Args:
                callback: A callable that takes an Operation and returns a WalkResult.
                walk_order: The order of traversal (PRE_ORDER or POST_ORDER).
-               op_class: If provided, only operations of this type are passed to the callback.)");
+               op_class: If provided, only operations of this type are passed to the callback.)")
+      .def("has_trait", [](PyOperationBase &self, nb::type_object &traitCls) {
----------------
rolfmorel wrote:

I think this means an op _instance_ is required, right? Would be nice if this was a classmethod instead.

In terms of the Python API, we could punt moving to a classmethod to a later PR as it just generalizes current usage. It's a bit unfortunate that we need to go through the CAPI though as there the API is supposed to have _some_ stability. So removing those functions when do move to using just `OperationName` is ... unfortunate.

What do you think, @PragmaTwice @makslevental ?

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


More information about the Mlir-commits mailing list