Skip to content

Commit e0d5ad7

Browse files
[mlir:python] Set __module__ classes generated by nanobind adaptors.
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. Signed-off-by: Ingo Müller <[email protected]>
1 parent 956cfa6 commit e0d5ad7

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

mlir/include/mlir/Bindings/Python/NanobindAdaptors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ class pure_subclass {
349349
thisClass = metaclass(derivedClassName, nanobind::make_tuple(superClass),
350350
attributes);
351351
scope.attr(derivedClassName) = thisClass;
352+
thisClass.attr("__module__") = scope.attr("__name__");
352353
}
353354

354355
template <typename Func, typename... Extra>

0 commit comments

Comments
 (0)