diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-05 15:09:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 15:09:11 (GMT) |
commit | dbc179e7c3c668537e7a61f36b8522545af08b56 (patch) | |
tree | 2de973003f0cde9d75e83057ddd5ae8766471d1e /Doc | |
parent | 83fc562ea5ff1d731cd1066016c16f9f75a12de4 (diff) | |
download | cpython-dbc179e7c3c668537e7a61f36b8522545af08b56.zip cpython-dbc179e7c3c668537e7a61f36b8522545af08b56.tar.gz cpython-dbc179e7c3c668537e7a61f36b8522545af08b56.tar.bz2 |
[3.12] Clarify that error messages are better with PEP 701 (GH-105150) (#105169)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/whatsnew/3.12.rst | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 3e8b866..a4c571e 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -203,6 +203,31 @@ same quote as the containing f-string. Let's cover these in detail: See :pep:`701` for more details. +As a positive side-effect of how this feature has been implemented (by parsing f-strings +with the PEG parser (see :pep:`617`), now error messages for f-strings are more precise +and include the exact location of the error. For example, in Python 3.11, the following +f-string raises a :exc:`SyntaxError`: + +.. code-block:: python + + >>> my_string = f"{x z y}" + f"{1 + 1}" + File "<stdin>", line 1 + (x z y) + ^^^ + SyntaxError: f-string: invalid syntax. Perhaps you forgot a comma? + +but the error message doesn't include the exact location of the error withing the line and +also has the expression artificially surrounded by parentheses. In Python 3.12, as f-strings +are parsed with the PEG parser, error messages can be more precise and show the entire line: + +.. code-block:: python + + >>> my_string = f"{x z y}" + f"{1 + 1}" + File "<stdin>", line 1 + my_string = f"{x z y}" + f"{1 + 1}" + ^^^ + SyntaxError: invalid syntax. Perhaps you forgot a comma? + (Contributed by Pablo Galindo, Batuhan Taskaya, Lysandros Nikolaou, Cristián Maureira-Fredes and Marta Gómez in :gh:`102856`. PEP written by Pablo Galindo, Batuhan Taskaya, Lysandros Nikolaou and Marta Gómez). |