From 5b7ba977400f314b0101d5b1c8ae6e59358721a6 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 23 Apr 2025 14:15:50 +0100 Subject: [PATCH 1/2] gh-132449: Add whatsnew entry for typos in keywords Signed-off-by: Pablo Galindo --- Doc/whatsnew/3.14.rst | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 63a5bab7fe8fea..6cd965e708829c 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -264,6 +264,49 @@ is unchanged. Improved error messages ----------------------- +* The interpreter now provides helpful suggestions when it detects typos in Python + keywords. When a word that closely resembles a Python keyword is encountered, + the interpreter will suggest the correct keyword in the error message. This + feature helps programmers quickly identify and fix common typing mistakes. For + example: + + .. code-block:: python + + >>> whille True: + ... pass + Traceback (most recent call last): + File "", line 1 + whille True: + ^^^^^^ + SyntaxError: invalid syntax. Did you mean 'while'? + + >>> asynch def fetch_data(): + ... pass + Traceback (most recent call last): + File "", line 1 + asynch def fetch_data(): + ^^^^^^ + SyntaxError: invalid syntax. Did you mean 'async'? + + >>> async def foo(): + ... awaid fetch_data() + Traceback (most recent call last): + File "", line 2 + awaid fetch_data() + ^^^^^ + SyntaxError: invalid syntax. Did you mean 'await'? + + >>> raisee ValueError("Error") + Traceback (most recent call last): + File "", line 1 + raisee ValueError("Error") + ^^^^^^ + SyntaxError: invalid syntax. Did you mean 'raise'? + + While the feature focuses on the most common cases, some variations of + misspellings may still result in regular syntax errors. (Contributed by Pablo + Galindo in :gh:`132449`.) + * When unpacking assignment fails due to incorrect number of variables, the error message prints the received number of values in more cases than before. (Contributed by Tushar Sadhwani in :gh:`122239`.) From 56a33dff1a94ac505b210a88c8f8e09893bf7f0d Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Wed, 23 Apr 2025 14:19:13 +0100 Subject: [PATCH 2/2] Update Doc/whatsnew/3.14.rst Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 6cd965e708829c..0f73b0e73195ee 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -304,8 +304,8 @@ Improved error messages SyntaxError: invalid syntax. Did you mean 'raise'? While the feature focuses on the most common cases, some variations of - misspellings may still result in regular syntax errors. (Contributed by Pablo - Galindo in :gh:`132449`.) + misspellings may still result in regular syntax errors. + (Contributed by Pablo Galindo in :gh:`132449`.) * When unpacking assignment fails due to incorrect number of variables, the error message prints the received number of values in more cases than before.