[Mlir-commits] [mlir] [mlir][python] expose isAttached (PR #153045)
Maksim Levental
llvmlistbot at llvm.org
Mon Aug 11 09:28:04 PDT 2025
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/153045
>From d90c0aa88c8d033c119908dba6b41320b9a5ad4b Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Mon, 11 Aug 2025 12:08:16 -0400
Subject: [PATCH] [mlir][python] expose isAttached
---
mlir/lib/Bindings/Python/IRCore.cpp | 8 ++++++++
mlir/python/mlir/_mlir_libs/_mlir/ir.pyi | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 5feed95f96f53..ee88aa4753d00 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -3442,6 +3442,14 @@ void mlir::python::populateIRCore(nb::module_ &m) {
return operation.createOpView();
},
"Detaches the operation from its parent block.")
+ .def_prop_ro(
+ "attached",
+ [](PyOperationBase &self) {
+ PyOperation &operation = self.getOperation();
+ operation.checkValid();
+ return operation.isAttached();
+ },
+ "Reports if the operation is attached to its parent block.")
.def("erase", [](PyOperationBase &self) { self.getOperation().erase(); })
.def("walk", &PyOperationBase::walk, nb::arg("callback"),
nb::arg("walk_order") = MlirWalkPostOrder);
diff --git a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
index be71737e4b5b4..dcae3dd742940 100644
--- a/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
+++ b/mlir/python/mlir/_mlir_libs/_mlir/ir.pyi
@@ -194,6 +194,13 @@ class _OperationBase:
"""
Detaches the operation from its parent block.
"""
+
+ @property
+ def attached(self) -> bool:
+ """
+ Reports if the operation is attached to its parent block.
+ """
+
def erase(self) -> None: ...
@overload
More information about the Mlir-commits
mailing list