From 1db6345b09c270d9059b96d5edb192612e409157 Mon Sep 17 00:00:00 2001 From: Blesson Date: Fri, 10 Apr 2026 15:01:37 +0530 Subject: [PATCH 1/2] Update syntax error example in tutorial Clarify error message explanation for syntax errors. --- Doc/tutorial/errors.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 3c6edf2c4793ab..33f86d45969943 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -17,16 +17,17 @@ Syntax Errors Syntax errors, also known as parsing errors, are perhaps the most common kind of complaint you get while you are still learning Python:: - >>> while True print('Hello world') + >>> a[1]] = 0 File "", line 1 - while True print('Hello world') - ^^^^^ - SyntaxError: invalid syntax - -The parser repeats the offending line and displays little arrows pointing -at the place where the error was detected. Note that this is not always the -place that needs to be fixed. In the example, the error is detected at the -function :func:`print`, since a colon (``':'``) is missing just before it. + a[1]] = 0 + ^ + SyntaxError: unmatched ']' + +The parser repeats the offending line and displays a little arrow pointing +at the earliest point in the line where the error was detected. +Note that this is not always the place that needs to be fixed. +In the example, the arrow points to the extra ``]`` bracket, which is where the +error is detected. The file name (```` in our example) and line number are printed so you know where to look in case the input came from a file. From 7963447662c96ae229307d5b856dc8e730a92cbd Mon Sep 17 00:00:00 2001 From: Blesson Date: Fri, 10 Apr 2026 15:03:57 +0530 Subject: [PATCH 2/2] Update syntax error example in tutorial Fix formatting issues in error message example --- Doc/tutorial/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 33f86d45969943..15eba6ba4e4ab0 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -20,7 +20,7 @@ complaint you get while you are still learning Python:: >>> a[1]] = 0 File "", line 1 a[1]] = 0 - ^ + ^ SyntaxError: unmatched ']' The parser repeats the offending line and displays a little arrow pointing