[Mlir-commits] [mlir] ffd341d - [MLIR] [Python] Added a missing cast to `__repr__` in the adaptors (#182867)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Feb 24 02:50:32 PST 2026
Author: Sergei Lebedev
Date: 2026-02-24T10:50:27Z
New Revision: ffd341d670281cae7d4eb688e9aaffc98364833a
URL: https://github.com/llvm/llvm-project/commit/ffd341d670281cae7d4eb688e9aaffc98364833a
DIFF: https://github.com/llvm/llvm-project/commit/ffd341d670281cae7d4eb688e9aaffc98364833a.diff
LOG: [MLIR] [Python] Added a missing cast to `__repr__` in the adaptors (#182867)
Without it the return type is inferred as `nanobind::object` which
results in invalid type stubs, since `__repr__` must return `str`.
Added:
Modified:
mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
Removed:
################################################################################
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