<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/127518>127518</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir][python] Types created by `mlir_type_subclass` are ignored by `nanobind`'s `stubgen`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            jpienaar
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ingomueller-net
      </td>
    </tr>
</table>

<pre>
    If we expose an `mlir::Type` to Python using `mlir_type_subclass` (like [here](https://github.com/llvm/llvm-project/blob/6a30076/mlir/lib/Bindings/Python/DialectGPU.cpp#L33)), `nanobind`'s [`stubgen`](https://nanobind.readthedocs.io/en/latest/typing.html#stub-generation) does not create any output for that class. This is unlike functions using `nb::class_` (like [this example](https://nanobind.readthedocs.io/en/latest/api_core.html#_CPPv4I0DpEN8nanobind6class_3defER6class_PKcRR4FuncDpRK5Extra).

I believe that `stubgen` only creates typing information for a class if the `type(.)` of the class object is a subclass of `type` (according to [this](https://github.com/wjakob/nanobind/blob/ab05b016/src/stubgen.py#L845) test), which isn't the case for how `mlir_type_subclass` currently works.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUlN9vozgQx_-a4cUqMiYQeOCh3ZRTtadTVO09R7YZwK1jI9sk5b8_GZLu_djV3UlRopiZ4Tsff2e492owiA0UT8DY26TQcO6AMSgOCZ_DaF2jzGDPM2qN7sFgSITtlualJ1ck-DFZj4QbAiU9a-Ugf4T88dsyIZSUBEuOSxitIbNXZrgHncIy4cnPQmrufQwEVmn1jgSKpxEdQnEAVo0hTD4WZC2wdlBhnEUq7RlYq_Xl_vMwOfuGMgBrhbYCWFvynNJ9CaxdFbFWq3j8pEynzOCBtZsoYO1BcY0y_HL8PZXTBCz_Nc-B1evnS5RruLFCmQ5KCmzvo0AoqQ-zGNDEwx8oveekDnkXRuys9KmywFqM79Q8oI9ywzIpM6RjOGtgeaz5MKBBx4OK4mrSWfTE2ECkQx4i5oXYOUxzIL11JIw8kBVhSr6NyhPlyWxWjv1sZKziv4M3YrubNeH0N-ghpuMHP0_6h_D_a0t8UidpHd6bOn05Hi-7F3qYnn-r7kXKTULeYf_8evtz_CpfX3ftbORhev1aPH8Ex4HVKdBHoI8vRKBWeMGt57_cALFGLzdCnmxMiTK9decV5IqKb5yI6kkYMRaIFgRWpfGqY5HtwRZlRTRUxMnJ3aUx4p62seNSWhcdFW1-Y_ivxr2-8ffVpJ_G-rQtF7QQNIu-9U7G763HdFqiMatdET2xgV7teR2VHInyBtg-bPK5x7Xf0V5_Pmxydg5N0Au5Wvfu06Rr8q7Oa55gk-3zuspoUdFkbGhdMl4VtC5lzcuiFF1VUJ73u7zvqozxRDWMsoKybJ-Vu5zStOyExJJmJfKdFD3CjuKZK53GSU2tGxLl_YxNxvZFViWaC9T-tny2YV0Xj2vWyRbz4GFHtfLBf68QVNDrwloTigMUT9M2z8WBxM3jb27oiFh-ToE7JGow1n3G_WPW_2yzZHa6-d8bae02bpxbw5eG_REAAP__GXLFrQ">