Skip to content

Escape triple quotes in generated Python docstrings - #237

Merged
dicej merged 2 commits into
bytecodealliance:mainfrom
cestercian:cursor/escape-python-docstring-quotes-8bab
Aug 25, 2026
Merged

Escape triple quotes in generated Python docstrings#237
dicej merged 2 commits into
bytecodealliance:mainfrom
cestercian:cursor/escape-python-docstring-quotes-8bab

Conversation

@cestercian

Copy link
Copy Markdown
Contributor

WIT /// documentation that contains """ was copied verbatim into generated Python """...""" docstrings, which is a SyntaxError (python -m py_compile fails).

Fixes #194

Summary

Generated Python bindings are now valid even when WIT docs include """ (and when they include both """ and '''). Documentation text is preserved.

Changes

  • Update docstring() in src/summary.rs to pick a triple-quote delimiter that does not appear in the docs. If both """ and ''' are present, escape """ as \"\"\" and wrap with """.
  • Add a bindings regression test using the issue WIT (plus a function whose docs contain both quote styles). The test generates stubs, ast.parses the output (so invalid Python fails), and asserts the documentation text is still present.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --tests -- -D warnings
  • cargo test --test bindings docstring_triple_quotes_are_valid_python — passed

cursoragent and others added 2 commits August 25, 2026 14:44
WIT docs containing """ were copied into Python """...""" strings,
producing a SyntaxError. Choose a delimiter that is not present in
the docs, or escape """ when both """ and ''' appear.

Co-authored-by: Cestercian <yashafaid@gmail.com>
Replacing """ as a sequence left a trailing quote on """", which
closed the generated string. When both quote styles are present,
escape backslashes first and then every double quote.

Co-authored-by: Cestercian <yashafaid@gmail.com>

@dicej dicej left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dicej
dicej merged commit 31ac56e into bytecodealliance:main Aug 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

componentize-py: WIT docs containing """ break generated Python bindings

3 participants