Skip to content

gh-160886: Doc: Clarify newline escaping in triple-quoted strings - #160887

Open
prodehghan wants to merge 1 commit into
python:mainfrom
prodehghan:clarify-triple-qouted-newline
Open

prodehghan wants to merge 1 commit into
python:mainfrom
prodehghan:clarify-triple-qouted-newline

Conversation

@prodehghan

@prodehghan prodehghan commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Clarify that unescaped newlines are preserved in triple-quoted strings and that "\<newline>" omits them in non-raw string literals. Retain string literal concatenation as an alternative.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35497173 | 📁 Comparing c33f25e against main (7e5227f)

  🔍 Preview build  

1 file changed
± reference/lexical_analysis.html

Comment thread Doc/reference/lexical_analysis.rst Outdated
where unescaped newlines are otherwise preserved. It allows long string
literals to be split across source lines without adding newline characters
to the resulting string. Alternatively, the same result can be achieved
using parentheses and :ref:`string literal concatenation <string-concatenation>`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As I said on the issue, I think the proper fix is to fix the reference so that it points to section 2.5.1. Triple-quoted strings, which has the sentence "Unescaped newlines are also allowed and retained", instead of to the generic 2.5. String and Bytes literals.

After adding new reference target line ..triple-quoted-strings after the current index line 677 single: '''; string literal, fix the link here and otherwise leave the line alone:

Suggested change
using parentheses and :ref:`string literal concatenation <string-concatenation>`.
The same result can be achieved using :ref:`triple-quoted strings <triple-quoted-strings>`,
or parentheses and :ref:`string literal concatenation <string-concatenation>`.

I am presuming that hyphens are correct for multi-word targets.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. Please see my comment on the PR.
I updated the text and fixed the reference.
I added a reference label for the "Triple-quoted strings" subsection, but I'm not sure that's the only way we can reference the subsection. Can we do it without introducing a label?

@bedevere-app

bedevere-app Bot commented Oct 29, 2026

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Clarify that unescaped newlines are preserved in triple-quoted strings and
that `"\<newline>"` omits them in non-raw string literals.
Retain string literal concatenation as an alternative.
@prodehghan
prodehghan force-pushed the clarify-triple-qouted-newline branch from c33f25e to 969876e Compare October 29, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants