Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit d821c80

Browse files
[mlir][python] Make types in register_(dialect|operation) more narrow. (#115307)
This PR makes the `pyClass`/`dialectClass` arguments of the pybind11 functions `register_dialect` and `register_operation` as well as their return types more narrow, concretely, a `py::type` instead of a `py::object`. As the name of the arguments indicate, they have to be called with a type instance (a "class"). The PR also updates the typing stubs of these functions (in the corresponding `.pyi` file), such that static type checkers are aware of the changed type. With the previous typing information, `pyright` raised errors on code generated by tablegen. Signed-off-by: Ingo Müller <[email protected]>
1 parent f4e2cf5 commit d821c80

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

MainModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ PYBIND11_MODULE(_mlir, m) {
5858
// Registration decorators.
5959
m.def(
6060
"register_dialect",
61-
[](py::object pyClass) {
61+
[](py::type pyClass) {
6262
std::string dialectNamespace =
6363
pyClass.attr("DIALECT_NAMESPACE").cast<std::string>();
6464
PyGlobals::get().registerDialectImpl(dialectNamespace, pyClass);
@@ -68,9 +68,9 @@ PYBIND11_MODULE(_mlir, m) {
6868
"Class decorator for registering a custom Dialect wrapper");
6969
m.def(
7070
"register_operation",
71-
[](const py::object &dialectClass, bool replace) -> py::cpp_function {
71+
[](const py::type &dialectClass, bool replace) -> py::cpp_function {
7272
return py::cpp_function(
73-
[dialectClass, replace](py::object opClass) -> py::object {
73+
[dialectClass, replace](py::type opClass) -> py::type {
7474
std::string operationName =
7575
opClass.attr("OPERATION_NAME").cast<std::string>();
7676
PyGlobals::get().registerOperationImpl(operationName, opClass,

0 commit comments

Comments
 (0)