[Mlir-commits] [mlir] [mlir:python] Set `__module__` classes generated by nanobind adaptors. (PR #127584)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Feb 17 23:48:18 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Ingo Müller (ingomueller-net)
<details>
<summary>Changes</summary>
This PR sets the `__module__` attribute of the classes generated by the nanobind adaptors for attributes, types, and values (via `mlir_(attribute|type|value)_subclass`). By default, the `__module__` property is set to `importlib._bootstrap`, which isn't where we want the new class to live. The new logic sets the property to the name of the module provided as `scope` instead. This also makes nanobind's `stubgen` generate stubs for those classes properly, which ignores classes whose `__module__` does not correspond to the module it is generating stubs for. This resolves #<!-- -->127518.
---
Full diff: https://github.com/llvm/llvm-project/pull/127584.diff
1 Files Affected:
- (modified) mlir/include/mlir/Bindings/Python/NanobindAdaptors.h (+1)
``````````diff
diff --git a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
index 517351cac6dbc..11338b2d49308 100644
--- a/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
+++ b/mlir/include/mlir/Bindings/Python/NanobindAdaptors.h
@@ -349,6 +349,7 @@ class pure_subclass {
thisClass = metaclass(derivedClassName, nanobind::make_tuple(superClass),
attributes);
scope.attr(derivedClassName) = thisClass;
+ thisClass.attr("__module__") = scope.attr("__name__");
}
template <typename Func, typename... Extra>
``````````
</details>
https://github.com/llvm/llvm-project/pull/127584
More information about the Mlir-commits
mailing list