python / python/cpython

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

未关闭
#154,970 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 PR #151375 及现有的 SyntaxError 建议实现,以了解如何检测独立语句中的运算符拼写错误。将此行为扩展到 ifwhile 和其他条件情况,然后添加或更新涵盖这些形式的测试,并验证建议的消息。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
compilers
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。