The text about escaping newlines in triple-qouted strings is misleading

Offen
#160,886 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
1/100
Issue-Typ
Dokumentation
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
documentation

Rechercherichtung

Read section 2.5.4.1 of the lexical analysis documentation at docs.python.org/3.16/reference/lexical_analysis.html#string-escape-ignore. Clarify that unescaped newlines in triple-quoted strings are retained and that omitting a newline requires a backslash-newline escape in both single- and triple-quoted strings. Check the wording against the examples in that section; the issue says the reporter is creating a PR and lists linked PR #160887.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

docs
Documentation

File: https://docs.python.org/3.16/reference/lexical_analysis.html#string-escape-ignore
Section 2.5.4.1 says:

A backslash can be added at the end of a line to ignore the newline:
(code sample)
The same result can be achieved using triple-quoted strings, or parentheses and string literal concatenation.

The current wording suggests that triple-quoted strings alone can split text across source lines without preserving newlines. In fact, unescaped newlines are retained, and omitting them requires the same backslash-newline escape used in ordinary string literals.

I suggest improving the text and clarifying that escaping newlines works the same in single- or triple-qouted string.

I'm creating the PR.

Linked PRs
  • gh-160887
Vorherrschende Sprache
Python
Sterne
77.8k
Forks
37.7k
Ø Merge
15 Std. 24 Min.
Gemergte PRs (30 T.)
728

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.