[Mlir-commits] [mlir] [MLIR][Python] Add Python and C API of `mlir::DynamicType` (PR #182751)

Rolf Morel llvmlistbot at llvm.org
Sun Feb 22 14:46:42 PST 2026


================
@@ -841,6 +842,61 @@ void PyOpaqueType::bindDerived(ClassTy &c) {
       "Returns the data for the Opaque type as a string.");
 }
 
+void PyDynamicType::bindDerived(ClassTy &c) {
+  c.def_static(
+      "get",
+      [](const std::string &fullTypeName, const std::vector<PyAttribute> &attrs,
+         DefaultingPyMlirContext context) {
+        size_t dotPos = fullTypeName.find('.');
+        if (dotPos == std::string::npos) {
+          throw nb::value_error("Expected full type name to be in the format "
+                                "'<dialectName>.<typeName>'.");
+        }
+
+        std::string dialectName = fullTypeName.substr(0, dotPos);
+        std::string typeName = fullTypeName.substr(dotPos + 1);
+        PyDialects dialects(context->getRef());
+        MlirDialect dialect = dialects.getDialectForKey(dialectName, false);
+        if (!mlirDialectIsAExtensibleDialect(dialect)) {
+          throw nb::value_error(
+              ("Dialect '" + dialectName + "' is not an extensible dialect.")
+                  .c_str());
+        }
----------------
rolfmorel wrote:

```suggestion
        if (!mlirDialectIsAExtensibleDialect(dialect))
          throw nb::value_error(
              ("Dialect '" + dialectName + "' is not an extensible dialect.")
                  .c_str());
```
Though it's up to taste whether this single statement is "simple" or not. 

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


More information about the Mlir-commits mailing list