python / python/cpython

Make "perhaps you missed a comma?" hint in syntax warnings less cryptic

未关闭
#140,764 11 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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

描述

Feature or enhancement

Proposal:

Syntax warnings for code like [][""], [](), and 1[2] finish with the hint "perhaps you missed a comma?"

>>> lambda: 1[2]
<python-input-23>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
<function <lambda> at 0x705dfb04b920>

When this came up in a review of currently emitted syntax warnings, it took me a moment to realise that it was suggesting the two subexpressions might have been supposed to be separate items in a sequence definition.

While I expect this would be clearer in the context of an actual warning, in isolation it felt very cryptic. Perhaps it would make sense to expand the hint to "did you miss a comma to separate sequence elements?"

Edit: Amended proposed text as @hugovk suggested

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-140893
  • gh-143278

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先查看链接的 PR gh-140893 和 gh-143278,然后检查 [][""][]()1[2] 等示例的语法警告行为。完成的标准是:警告提示清楚地说明序列元素之间可能缺少逗号,同时相关警告示例仍按预期运行。

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

评估

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

把新 issue 发到你的邮箱

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