[Mlir-commits] [mlir] [MLIR][Python] Add docstring for generated python op classes (PR #158198)

Maksim Levental llvmlistbot at llvm.org
Thu Sep 11 23:02:41 PDT 2025


makslevental wrote:

So this is great but I'm worried there could be other illegal characters in people's descriptions (and then this change would break them). For example:

```python
class DescriptionOp:
  """
  This is a long description.
  It has multiple lines.
  A code block (to test the indent).
  \`\`\`mlir
  test.loop {
    test.yield
  }
  \`\`\`
  Add \"\"\" will not terminate the description.
  c:\users\me\stuff.
  """
  pass

print(DescriptionOp.__doc__)
```

(ignore that I had to escape the backticks here for legal markdown).

This produces

```
/Users/mlevental/miniforge3/envs/iree/bin/python /Users/mlevental/dev_projects/llvm-project/demo.py 
  File "/Users/mlevental/dev_projects/llvm-project/demo.py", line 13
    """
       ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 195-196: truncated \uXXXX escape
```

On the otherhand using a raw docstring

```python
class DescriptionOp:
  r"""
  This is a long description.
  It has multiple lines.
  A code block (to test the indent).
  \`\`\`mlir
  test.loop {
    test.yield
  }
  \`\`\`
  Add \"\"\" will not terminate the description.
  c:\users\me\stuff.
  """
  pass

print(DescriptionOp.__doc__)
```

prints

```
  This is a long description.
  It has multiple lines.
  A code block (to test the indent).
  \`\`\`mlir
  test.loop {
    test.yield
  }
  \`\`\`
  Add \"\"\" will not terminate the description.
  c:\users\me\stuff.
```

So I think we should just be safe and emit raw docstrings.

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


More information about the Mlir-commits mailing list