diff --git a/mlir/lib/Bindings/Python/IRModules.cpp b/mlir/lib/Bindings/Python/IRModules.cpp --- a/mlir/lib/Bindings/Python/IRModules.cpp +++ b/mlir/lib/Bindings/Python/IRModules.cpp @@ -1228,13 +1228,12 @@ } /// Returns `index`-th element in the result list. - PyOpResult dunderGetItem(intptr_t index) { + PyValue dunderGetItem(intptr_t index) { if (index < 0 || index >= dunderLen()) { throw SetPyError(PyExc_IndexError, "attempt to access out of bounds region"); } - PyValue value(operation, mlirOperationGetOperand(operation->get(), index)); - return PyOpResult(value); + return PyValue(operation, mlirOperationGetOperand(operation->get(), index)); } /// Defines a Python class in the bindings. diff --git a/mlir/test/Bindings/Python/ir_operation.py b/mlir/test/Bindings/Python/ir_operation.py --- a/mlir/test/Bindings/Python/ir_operation.py +++ b/mlir/test/Bindings/Python/ir_operation.py @@ -132,6 +132,29 @@ run(testBlockArgumentList) +# CHECK-LABEL: TEST: testOperationOperands +def testOperationOperands(): + with Context() as ctx: + ctx.allow_unregistered_dialects = True + module = Module.parse(r""" + func @f1(%arg0: i32) { + %0 = "test.producer"() : () -> i64 + "test.consumer"(%arg0, %0) : (i32, i64) -> () + return + }""") + func = module.body.operations[0] + entry_block = func.regions[0].blocks[0] + consumer = entry_block.operations[1] + assert len(consumer.operands) == 2 + # CHECK: Operand 0, type i32 + # CHECK: Operand 1, type i64 + for i, operand in enumerate(consumer.operands): + print(f"Operand {i}, type {operand.type}") + + +run(testOperationOperands) + + # CHECK-LABEL: TEST: testDetachedOperation def testDetachedOperation(): ctx = Context()