From fd300cdd65f011ef7f1ec313eeb226bf2bb17624 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Thu, 18 Aug 2022 13:48:19 +0200 Subject: [PATCH 1/3] gh-95994: clarify escaped newlines. --- Doc/reference/lexical_analysis.rst | 34 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index b76b4688413eee..4dc3692c609272 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -552,7 +552,7 @@ Standard C. The recognized escape sequences are: +-----------------+---------------------------------+-------+ | Escape Sequence | Meaning | Notes | +=================+=================================+=======+ -| ``\newline`` | Backslash and newline ignored | | +| ``\`` | Backslash and newline ignored | \(1) | +-----------------+---------------------------------+-------+ | ``\\`` | Backslash (``\``) | | +-----------------+---------------------------------+-------+ @@ -574,10 +574,10 @@ Standard C. The recognized escape sequences are: +-----------------+---------------------------------+-------+ | ``\v`` | ASCII Vertical Tab (VT) | | +-----------------+---------------------------------+-------+ -| ``\ooo`` | Character with octal value | (1,3) | +| ``\ooo`` | Character with octal value | (2,4) | | | *ooo* | | +-----------------+---------------------------------+-------+ -| ``\xhh`` | Character with hex value *hh* | (2,3) | +| ``\xhh`` | Character with hex value *hh* | (3,4) | +-----------------+---------------------------------+-------+ Escape sequences only recognized in string literals are: @@ -585,19 +585,31 @@ Escape sequences only recognized in string literals are: +-----------------+---------------------------------+-------+ | Escape Sequence | Meaning | Notes | +=================+=================================+=======+ -| ``\N{name}`` | Character named *name* in the | \(4) | +| ``\N{name}`` | Character named *name* in the | \(5) | | | Unicode database | | +-----------------+---------------------------------+-------+ -| ``\uxxxx`` | Character with 16-bit hex value | \(5) | +| ``\uxxxx`` | Character with 16-bit hex value | \(6) | | | *xxxx* | | +-----------------+---------------------------------+-------+ -| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(6) | +| ``\Uxxxxxxxx`` | Character with 32-bit hex value | \(7) | | | *xxxxxxxx* | | +-----------------+---------------------------------+-------+ Notes: (1) + A backslash can be added at the end of a line to ignore the newline:: + + >>> 'This string will not include \ + ... backslashes or newline characters.' + 'This string will not include backslashes or newline characters.' + + The same result can be achieved by using parentheses and :ref:`string + literals concatenation ` or :ref:`triple-quoted + strings `. + + +(2) As in Standard C, up to three octal digits are accepted. .. versionchanged:: 3.11 @@ -605,22 +617,22 @@ Notes: In a future Python version they will be a :exc:`SyntaxWarning` and eventually a :exc:`SyntaxError`. -(2) +(3) Unlike in Standard C, exactly two hex digits are required. -(3) +(4) In a bytes literal, hexadecimal and octal escapes denote the byte with the given value. In a string literal, these escapes denote a Unicode character with the given value. -(4) +(5) .. versionchanged:: 3.3 Support for name aliases [#]_ has been added. -(5) +(6) Exactly four hex digits are required. -(6) +(7) Any Unicode character can be encoded this way. Exactly eight hex digits are required. From ec8b6aea865a0adef6566276f992d0fb7bcdeda5 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Sun, 21 Aug 2022 18:18:14 +0200 Subject: [PATCH 2/3] Rephrase ambiguous sentence. Co-authored-by: C.A.M. Gerlach --- Doc/reference/lexical_analysis.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 4dc3692c609272..8e032d1d2d9540 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -604,9 +604,8 @@ Notes: ... backslashes or newline characters.' 'This string will not include backslashes or newline characters.' - The same result can be achieved by using parentheses and :ref:`string - literals concatenation ` or :ref:`triple-quoted - strings `. + The same result can be achieved using :ref:`triple-quoted strings `, + or parentheses and :ref:`string literal concatenation `. (2) From 39fcfc14d9f13fa99c4762afe5920a512604e46a Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Fri, 26 Aug 2022 20:41:43 +0200 Subject: [PATCH 3/3] Use `` in escape sequences table. Co-authored-by: C.A.M. Gerlach --- Doc/reference/lexical_analysis.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 8e032d1d2d9540..8fd8d70426a8b4 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -552,7 +552,7 @@ Standard C. The recognized escape sequences are: +-----------------+---------------------------------+-------+ | Escape Sequence | Meaning | Notes | +=================+=================================+=======+ -| ``\`` | Backslash and newline ignored | \(1) | +| ``\``\ | Backslash and newline ignored | \(1) | +-----------------+---------------------------------+-------+ | ``\\`` | Backslash (``\``) | | +-----------------+---------------------------------+-------+