Escape triple quotes in generated Python docstrings - #237
Merged
dicej merged 2 commits intoAug 25, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIT
///documentation that contains"""was copied verbatim into generated Python"""..."""docstrings, which is aSyntaxError(python -m py_compilefails).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
docstring()insrc/summary.rsto pick a triple-quote delimiter that does not appear in the docs. If both"""and'''are present, escape"""as\"\"\"and wrap with""".ast.parses the output (so invalid Python fails), and asserts the documentation text is still present.Testing
cargo fmt --all -- --checkcargo clippy --all-targets --tests -- -D warningscargo test --test bindings docstring_triple_quotes_are_valid_python— passed