[Mlir-commits] [mlir] [MLIR][Python] Improve Iterator performance. Don't `throw` in `dunderNext` methods. (PR #175377)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jan 11 00:27:22 PST 2026


================
@@ -194,13 +194,14 @@ nb::object PyBlock::getCapsule() {
 // Collections.
 //------------------------------------------------------------------------------
 
-PyRegion PyRegionIterator::dunderNext() {
+nb::typed<nb::object, PyRegion> PyRegionIterator::dunderNext() {
----------------
MaPePeR wrote:

Sadly, that does not work, as nanobind infers the return type as `Region | None` then and converts the `std::nullopt` case to `None`, which triggers a `SystemError: <nanobind.nb_method object at ...> returned a result with an exception set` [from CPython](https://github.com/python/cpython/blob/aa8578dc54df2af9daa3353566359e602e5905cf/Objects/call.c#L49-L61).

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


More information about the Mlir-commits mailing list