Skip to content

gh-148327: Update syntax error example in tutorial#148328

Open
blesson-07 wants to merge 5 commits intopython:mainfrom
blesson-07:main
Open

gh-148327: Update syntax error example in tutorial#148328
blesson-07 wants to merge 5 commits intopython:mainfrom
blesson-07:main

Conversation

@blesson-07
Copy link
Copy Markdown

@blesson-07 blesson-07 commented Apr 10, 2026

gh-148327: Update syntax error example in tutorial

Closes #148327

Replace the outdated syntax error example with a clearer one.
Update the syntax error example from while True print('Hello world') to a[1]] = 0, which gives a clearer unmatched ']' error and better shows arrow placement.

Clarify error message explanation for syntax errors.
Fix formatting issues in error message example
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 10, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@StanFromIreland
Copy link
Copy Markdown
Member

CC @erlend-aasland, per #30097 (comment)

Copy link
Copy Markdown
Contributor

@sharktide sharktide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, left one wording suggestion. Up to you if you want to take it :)

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
at the earliest point in the line where the error was detected.
at the earliest point in the line in which the error was detected.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Where" seemed fine to me, but that's purely opinion.

@Andrew5057
Copy link
Copy Markdown

Andrew5057 commented Apr 11, 2026

I think I'm actually -1 here.

First, what makes the example outdated? I get the following:

>>> while True print('Hello world')
  File "<python-input-0>", line 1
    while True print('Hello world')
               ^^^^^
SyntaxError: invalid syntax

that closely matches what the documentation currently has:

>>> while True print('Hello world')
  File "<stdin>", line 1
    while True print('Hello world')
               ^^^^^
SyntaxError: invalid syntax

So I'm not sure what the "outdated" here refers to. The "python-input-0" is maybe worth changing, but I don't think the while-loop stuff is.

Second, I think the old example is clearer than the new one. The tutorial contains this paragraph:

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 print(), since a colon (':') is missing just before it.

The original while loop example is a deliberate choice to show the misleading arrow placement; it's useful to see that the arrows are at print() even though the problem is before that. This new example loses that nuance since the arrow shows you exactly what you're supposed to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Docs: problem with page "8. Errors and Exceptions"

4 participants