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

Aberta
#160,886 3 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
1/5
Tempo estimado
Menos de uma hora
Facilidade para iniciantes
1/100
Tipo de issue
Documentação
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
documentation

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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
Linguagem predominante
Python
Estrelas
77.8k
Forks
37.7k
Merge médio
17h 24min
PRs com merge (30d)
716

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.