[Mlir-commits] [mlir] [MLIR][Python] Improve Iterator performance. Don't `throw` in `dunderNext` methods. (PR #175377)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jan 13 07:50:33 PST 2026
================
@@ -327,13 +331,15 @@ void PyBlockList::bind(nb::module_ &m) {
nb::typed<nb::object, PyOpView> PyOperationIterator::dunderNext() {
parentOperation->checkValid();
if (mlirOperationIsNull(next)) {
- throw nb::stop_iteration();
+ PyErr_SetNone(PyExc_StopIteration);
+ // python functions should return NULL after setting any exception
+ return nb::object();
}
PyOperationRef returnOperation =
PyOperation::forOperation(parentOperation->getContext(), next);
next = mlirOperationGetNextInBlock(next);
- return returnOperation->createOpView();
+ return nb::cast(returnOperation->createOpView());
----------------
MaPePeR wrote:
Just noticed I dont need this `nb::cast`. Function already returned nb::typed<nb::object, PyOpView>` and `createOpView` returns `nb::object` already.
https://github.com/llvm/llvm-project/pull/175377
More information about the Mlir-commits
mailing list