GeezerVison is showing github.com — gh-140764: Improve syntax warning hint for missing commas by ayushm98 · Pull Request #143278 · python/cpython
Conversation
ayushm98
commented
Dec 29, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #140764
Summary
Makes the syntax warning hint clearer when detecting potentially missing commas in sequence literals.
Problem
Current warning: 'int' object is not subscriptable; perhaps you missed a comma?
This hint can be cryptic - it's not immediately obvious that it's suggesting the code might have been meant as separate items in a sequence.
Solution
New warning: 'int' object is not subscriptable; did you miss a comma to separate sequence elements?
Example
# Before:
>>> lambda: 1[2]
<input>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
# After:
>>> lambda: 1[2]
<input>:1: SyntaxWarning: 'int' object is not subscriptable; did you miss a comma to separate sequence elements?
Much clearer what the intended fix might be!
Changes
- Updated 3 warning messages in
Python/codegen.c:
- Callable check
- Subscriptable check
- Index type check
- Updated corresponding test regex patterns in
Lib/test/test_grammar.py
Test Plan
- All existing tests updated to match new message
- Warning still triggers in same cases, just with clearer text
- No behavioral changes, only message improvement
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Fixes python#140764
Changed the cryptic 'perhaps you missed a comma?' hint to the
clearer 'did you miss a comma to separate sequence elements?'
This makes the warning's intention more obvious when code like
`[]()`, `1[2]`, or `[][] ` triggers a syntax warning.
Updated error messages in Python/codegen.c for:
- callable check
- subscriptable check
- index type check
Updated corresponding tests in Lib/test/test_grammar.py to match
the new warning text.
|
The following commit authors need to sign the Contributor License Agreement:

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.
If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
StanFromIreland
changed the title
Improve syntax warning hint for missing commas
gh-140764: Improve syntax warning hint for missing commas
Dec 30, 2025
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Please don't open PRs when there is already one: #140893.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.