[Mlir-commits] [mlir] [mlir][python] value casting (PR #69644)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Mon Nov 6 02:52:56 PST 2023


================
@@ -93,6 +91,18 @@ PYBIND11_MODULE(_mlir, m) {
       },
       "typeid"_a, "type_caster"_a, "replace"_a = false,
       "Register a type caster for casting MLIR types to custom user types.");
+  m.def(
+      MLIR_PYTHON_CAPI_VALUE_CASTER_REGISTER_ATTR,
+      [](MlirTypeID mlirTypeID, bool replace) -> py::cpp_function {
+        return py::cpp_function(
+            [mlirTypeID, replace](py::object valueCaster) -> py::object {
+              PyGlobals::get().registerValueCaster(mlirTypeID, valueCaster,
+                                                   replace);
+              return valueCaster;
+            });
+      },
+      "typeid"_a, "replace"_a = false,
----------------
ftynse wrote:

Nit: how about making `replace` a keyword-only argument by passing `py::kw_only()` before it?

https://github.com/llvm/llvm-project/pull/69644


More information about the Mlir-commits mailing list