Skip to content

Commit 4f4e72f

Browse files
committed
Improve syntax warning hint for missing commas
Fixes #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.
1 parent b6b0e14 commit 4f4e72f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Lib/test/test_grammar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ def test_warn_missed_comma(self):
15201520
def check(test):
15211521
self.check_syntax_warning(test, msg)
15221522

1523-
msg=r'is not callable; perhaps you missed a comma\?'
1523+
msg=r'is not callable; did you miss a comma to separate sequence elements\?'
15241524
check('[(1, 2) (3, 4)]')
15251525
check('[(x, y) (3, 4)]')
15261526
check('[[1, 2] (3, 4)]')
@@ -1543,7 +1543,7 @@ def check(test):
15431543
check('[t"{x}" (3, 4)]')
15441544
check('[t"x={x}" (3, 4)]')
15451545

1546-
msg=r'is not subscriptable; perhaps you missed a comma\?'
1546+
msg=r'is not subscriptable; did you miss a comma to separate sequence elements\?'
15471547
check('[{1, 2} [i, j]]')
15481548
check('[{i for i in range(5)} [i, j]]')
15491549
check('[(i for i in range(5)) [i, j]]')
@@ -1557,7 +1557,7 @@ def check(test):
15571557
check('[t"{x}" [i, j]]')
15581558
check('[t"x={x}" [i, j]]')
15591559

1560-
msg=r'indices must be integers or slices, not tuple; perhaps you missed a comma\?'
1560+
msg=r'indices must be integers or slices, not tuple; did you miss a comma to separate sequence elements\?'
15611561
check('[(1, 2) [i, j]]')
15621562
check('[(x, y) [i, j]]')
15631563
check('[[1, 2] [i, j]]')

Python/codegen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3650,7 +3650,7 @@ check_caller(compiler *c, expr_ty e)
36503650
case Interpolation_kind: {
36513651
location loc = LOC(e);
36523652
return _PyCompile_Warn(c, loc, "'%.200s' object is not callable; "
3653-
"perhaps you missed a comma?",
3653+
"did you miss a comma to separate sequence elements?",
36543654
infer_type(e)->tp_name);
36553655
}
36563656
default:
@@ -3681,7 +3681,7 @@ check_subscripter(compiler *c, expr_ty e)
36813681
case Lambda_kind: {
36823682
location loc = LOC(e);
36833683
return _PyCompile_Warn(c, loc, "'%.200s' object is not subscriptable; "
3684-
"perhaps you missed a comma?",
3684+
"did you miss a comma to separate sequence elements?",
36853685
infer_type(e)->tp_name);
36863686
}
36873687
default:
@@ -3716,7 +3716,7 @@ check_index(compiler *c, expr_ty e, expr_ty s)
37163716
location loc = LOC(e);
37173717
return _PyCompile_Warn(c, loc, "%.200s indices must be integers "
37183718
"or slices, not %.200s; "
3719-
"perhaps you missed a comma?",
3719+
"did you miss a comma to separate sequence elements?",
37203720
infer_type(e)->tp_name,
37213721
index_type->tp_name);
37223722
}

0 commit comments

Comments
 (0)