[Mlir-commits] [mlir] [MLIR] [Python] Added return type to `__repr__` in the adaptors (PR #182867)
Sergei Lebedev
llvmlistbot at llvm.org
Tue Feb 24 02:25:31 PST 2026
https://github.com/superbobry updated https://github.com/llvm/llvm-project/pull/182867
>From d7ab9b63cc2876dac3ad7305d20665ac25da4b6f Mon Sep 17 00:00:00 2001
From: Sergei Lebedev <slebedev at google.com>
Date: Mon, 23 Feb 2026 15:12:23 +0000
Subject: [PATCH] [MLIR] [Python] Added return type to `__repr__` in the
adaptors
Without an explicit annotation the return type is inferred as nanobind::object
which results in invalid type stubs, since __repr__ must return str.
---
mlir/include/mlir/Bindings/Python/NanobindAdaptors.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
index 918030824c409..9b54baa5bd4b1 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
@@ -570,8 +570,9 @@ class mlir_attribute_subclass : public pure_subclass {
[isaFunction](MlirAttribute other) { return isaFunction(other); },
nanobind::arg("other_attribute"), nanobind::sig(kIsinstanceSig));
def("__repr__", [superCls, captureTypeName](nanobind::object self) {
- return nanobind::repr(superCls(self))
- .attr("replace")(superCls.attr("__name__"), captureTypeName);
+ return nanobind::cast<std::string>(
+ nanobind::repr(superCls(self))
+ .attr("replace")(superCls.attr("__name__"), captureTypeName));
});
if (getTypeIDFunction) {
def_staticmethod(
More information about the Mlir-commits
mailing list