python / python/cpython

Extend operator-typo SyntaxError suggestions (`=<`, `=>`, `=!`) to `if/while` other conditions

Open
#154,970 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Follow-up #151375

In that PR we added helpful SyntaxError messages for common operator typos: =< suggests <=, => suggests >=, and =! suggests !=.

These suggestions currently only work when the typo appears in a plain statement. like

'a => b' invalid syntax. Maybe you meant '>=' instead of '=>'?

So this is for extending in if, while, or other conditions:

These only fire for bare statements, so if a => b: still gives the generic error, no? That is probably fine for a first iteration (the = < tokenization makes it look like an assignment), but maybe we should add a test documenting it or a follow-up issue for the if/while case.

Originally posted by @pablogsal in https://github.com/python/cpython/pull/151375#discussion_r3683730462

I'm planning to work on this and submit a PR shortly after the follow up merged, please avoid PR in this

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading PR #151375 and its existing SyntaxError suggestion implementation to understand how the operator typos are detected for bare statements. Extend the behavior to the if, while, and other condition cases, then add or update tests covering those forms and verify the suggested messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.