Re: backslash in triple quoted string
"Peter J. Holzer" <[email protected]>
| Newsgroups | comp.lang.python |
|---|---|
| Message-ID | <[email protected]> |
On 2025-05-08 08:05:54 +0200, Left Right via Python-list wrote:
> Also, it appears that the change linked above is a lie:
Such strong words ...
> https://docs.python.org/3/reference/lexical_analysis.html#grammar-token-python-grammar-longstringitem
>
> According to the grammar, any character can follow backslash in a
> valid Python program. The warning / error raised by this code should
> not be a syntax error / warning because the syntax is correct.
Warnings are about technically correct but probably unintended usage.
The documentation you linked to describes (a bit further down) which
escape sequences are recognized and what happens if you use an
unrecognized escape sequence. It also mentions that using an
unrecognized escape sequence *will* be an error in future versions of
Python.
A warning is appropriate here. It gives the programmer a chance to fix
the program now before it breaks.
One could argue that it should say 'unrecognized escape sequence'
instead of 'invalid escape sequence', since it isn't invalid yet, but
that's nitpicking.
hjp
--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | [email protected] | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmggdNsACgkQ8g5IURL+ KF3CiQ/+M1YsR/nTAzRyauQ2RiUTR2hw3J3DFSpXSQhsvKvS7S1uPL1+kkBsoUCC 623bVF+5yrPsjAOJVm0S2ieT0465zvnBzDIqcTvKoNmHbAxc3HNEEUyORZ3PGLzN yG7TyUqTLgoHaMGbxEpPfZLQ3DLrslXVKX9JPpMoeDu5jaGah2fv1Y4opCU62Akj QlQP/9rj9k67CGPSr2ndnDu9fqL6v79p57IUC9/SVKOCCaYTG9Wz+LFIyvybP8qp nEfwU+qZw2tKKEn8r78JlP7WkpqBFV2vtmuvFCFsTYLPD7JHihyq9J8fiG1OKy5V t2EPCcFiXshcIUxgiWoEwhBD8NsuqLsvg9Z3z96BzJ8MDB6S6dbp0sLFOdpQiSPT xL7QRB3LvG8oyW63JNCkhuDhKhAf2yPCfezVAiZfcF6Ef3s+o+dv+L0alEXFTpJ1 YFVMlRv5+n/NLAZP7zdpEiNoRlZceTC955MznS40eK7Zc5QK99tzX1BYEBcTNeNR VmNmYma/a4FRo2mFiPFeAyTlDOOCw7G7a3NvRmchHrqWXTZ+WoPmDq/e1DeuDXgi 69Piv0YvwJ2BrN7Dj30R9DmC1Y8K5swg9aUJJNQw3Hamvzybwk94rhBFn1piViQv YAKAEH7NdGYssMgxEbMcqmCpavTVVen7ZxH4WNQ2BIRhs4iKvdY= =k/a9 -----END PGP SIGNATURE-----