Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Improve syntax error messages for keywords with typos #132449

Copy link
Copy link
Closed
@pablogsal

Description

@pablogsal
Issue body actions

Currently, when users make typos in Python keywords, they receive generic "invalid syntax" error messages without any helpful suggestions about what might be wrong. This creates a frustrating experience, especially for beginners who might not immediately recognize that they've misspelled a keyword.

For example, typing whille True: instead of while True: would currently result in a generic syntax error without any hint that the problem is a misspelled keyword.

I propose to start raising errors like these:

==================================================

Traceback (most recent call last):
  File "/home/pablogsal/github/python/main/check.py", line 18, in test_mistyped_program
    exec(code_example)
    ~~~~^^^^^^^^^^^^^^
  File "<string>", line 2
    asynch def fetch_data():
    ^^^^^^
SyntaxError: invalid syntax. Did you mean 'async'?

==================================================

Traceback (most recent call last):
  File "/home/pablogsal/github/python/main/check.py", line 18, in test_mistyped_program
    exec(code_example)
    ~~~~^^^^^^^^^^^^^^
  File "<string>", line 6
    result = awaid fetch_data()
             ^^^^^
SyntaxError: invalid syntax. Did you mean 'await'?

==================================================

finally:
Traceback (most recent call last):
  File "/home/pablogsal/github/python/main/check.py", line 18, in test_mistyped_program
    exec(code_example)
    ~~~~^^^^^^^^^^^^^^
  File "<string>", line 6
    finaly:
    ^^^^^^
SyntaxError: invalid syntax. Did you mean 'finally'?

==================================================

Traceback (most recent call last):
  File "/home/pablogsal/github/python/main/check.py", line 18, in test_mistyped_program
    exec(code_example)
    ~~~~^^^^^^^^^^^^^^
  File "<string>", line 4
    raisee ValueError("Value cannot be negative")
    ^^^^^^
SyntaxError: invalid syntax. Did you mean 'raise'?

==================================================

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.