From 722eafd2a53fb6c59798670358489f9e11ca6d50 Mon Sep 17 00:00:00 2001 From: Vivek Vashist Date: Tue, 14 Dec 2021 14:24:23 +1030 Subject: [PATCH 1/5] Fix the output of syntax error example --- Doc/tutorial/errors.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index f2490d65db5d49..456bddf531112b 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -18,10 +18,10 @@ 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') - File "", line 1 - while True print('Hello world') - ^ - SyntaxError: invalid syntax + File "", line 1 + while True print('Hello world') + ^^^^^^^^^^^^^^^^^^^^^^^^^ +SyntaxError: invalid syntax. Perhaps you forgot a comma? The parser repeats the offending line and displays a little 'arrow' pointing at the earliest point in the line where the error was detected. The error is From dc91d809f3502e328beb28c31e9f00e0e6599324 Mon Sep 17 00:00:00 2001 From: Vivek Vashist Date: Fri, 17 Dec 2021 09:43:36 +1030 Subject: [PATCH 2/5] Minor update to the sentence below the error message --- 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 456bddf531112b..7a7194b48528de 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -23,7 +23,7 @@ complaint you get while you are still learning Python:: ^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? -The parser repeats the offending line and displays a little 'arrow' pointing at +The parser repeats the offending line and displays a row of 'arrows' pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token *preceding* the arrow: in the example, the error is detected at the function :func:`print`, since a colon From 55ebf2d9bf36af2a8c710b8164bbdaacdd954189 Mon Sep 17 00:00:00 2001 From: Vivek Vashist Date: Sun, 9 Jan 2022 17:47:45 +1030 Subject: [PATCH 3/5] Add a better the Syntax Error example for PR##30097 --- Doc/tutorial/errors.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index c0e71f2bdcee10..029eab5fc6091c 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -16,14 +16,15 @@ 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') - File "", line 1 - while True print('Hello world') - ^^^^^^^^^^^^^^^^^^^^^^^^^ -SyntaxError: invalid syntax. Perhaps you forgot a comma? - -The parser repeats the offending line and displays a row of 'arrows' pointing at + + >>> greeting = 'Hello World' + >>> print greeting + File "", line 1 + print greeting + ^^^^^^^^^^^^^^ + SyntaxError: Missing parentheses in call to 'print'. Did you mean print(greeting)? + +The parser repeats the offending line and displays 'arrows' pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token *preceding* the arrow: in the example, the error is detected at the function :func:`print`, since a colon From ab47e7480654fb998e53dec9055d18eacbe4aa6f Mon Sep 17 00:00:00 2001 From: Vivek Vashist Date: Sun, 9 Jan 2022 21:37:21 +1030 Subject: [PATCH 4/5] Add Syntax Error example PR #30097 The quote used in the example is from Monty Python :) --- Doc/tutorial/errors.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 029eab5fc6091c..8dde3d13270b18 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -16,15 +16,13 @@ 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:: - - >>> greeting = 'Hello World' - >>> print greeting + >>> print('Are you suggesting that coconuts migrate?) File "", line 1 - print greeting - ^^^^^^^^^^^^^^ - SyntaxError: Missing parentheses in call to 'print'. Did you mean print(greeting)? - -The parser repeats the offending line and displays 'arrows' pointing at + print('Are you suggesting that coconuts migrate?) + ^ + SyntaxError: unterminated string literal (detected at line 1) + +The parser repeats the offending line and displays a little 'arrow' pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token *preceding* the arrow: in the example, the error is detected at the function :func:`print`, since a colon From 149c7ebe677ca1586367b07e57d799f159fc3644 Mon Sep 17 00:00:00 2001 From: Vivek Vashist Date: Wed, 5 Oct 2022 16:28:58 +1030 Subject: [PATCH 5/5] Update syntax error for #30097 --- Doc/tutorial/errors.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index ec885b84c694df..1bebcaa1258bd6 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -25,8 +25,8 @@ complaint you get while you are still learning Python:: The parser repeats the offending line and displays a little 'arrow' pointing at the earliest point in the line where the error was detected. The error is caused by (or at least detected at) the token *preceding* the arrow: in the -example, the error is detected at the function :func:`print`, since a colon -(``':'``) is missing before it. File name and line number are printed so you +example, the error is detected at the function :func:`print`, since a single quote +(``'``) is missing. Error message and line number is also printed so you know where to look in case the input came from a script.