python / python/cpython

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

Open
#140,764 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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

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

Review linked PRs gh-140893 and gh-143278 first, then inspect the syntax-warning behavior for examples such as [][""], [](), and 1[2]. Done means the warning hint clearly explains that a comma may be missing between sequence elements, with the relevant warning examples still behaving as intended.

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
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.