diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index ebcd98a0a37776..e07fad9c1017b2 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1525,7 +1525,7 @@ def test_warn_missed_comma(self): def check(test): self.check_syntax_warning(test, msg) - msg=r'is not callable; perhaps you missed a comma\?' + msg=r'is not callable; did you miss a comma to separate elements\?' check('[(1, 2) (3, 4)]') check('[(x, y) (3, 4)]') check('[[1, 2] (3, 4)]') @@ -1548,7 +1548,7 @@ def check(test): check('[t"{x}" (3, 4)]') check('[t"x={x}" (3, 4)]') - msg=r'is not subscriptable; perhaps you missed a comma\?' + msg=r'is not subscriptable; did you miss a comma to separate elements\?' check('[{1, 2} [i, j]]') check('[{i for i in range(5)} [i, j]]') check('[(i for i in range(5)) [i, j]]') @@ -1562,7 +1562,7 @@ def check(test): check('[t"{x}" [i, j]]') check('[t"x={x}" [i, j]]') - msg=r'indices must be integers or slices, not tuple; perhaps you missed a comma\?' + msg=r'indices must be integers or slices, not tuple; did you miss a comma to separate elements\?' check('[(1, 2) [i, j]]') check('[(x, y) [i, j]]') check('[[1, 2] [i, j]]') diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-12-07-10-37-32.gh-issue-140764.kABu5f.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-07-10-37-32.gh-issue-140764.kABu5f.rst new file mode 100644 index 00000000000000..0049aa5c83173d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-07-10-37-32.gh-issue-140764.kABu5f.rst @@ -0,0 +1 @@ +Improve the suggestion in syntax warning messages for potentially missing commas when defining containers. The messages now say "did you miss a comma to separate elements?" instead of "perhaps you missed a comma?". diff --git a/Python/codegen.c b/Python/codegen.c index 478fbec1cbadd0..32d650911c96e9 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -3673,7 +3673,7 @@ check_caller(compiler *c, expr_ty e) case Interpolation_kind: { location loc = LOC(e); return _PyCompile_Warn(c, loc, "'%.200s' object is not callable; " - "perhaps you missed a comma?", + "did you miss a comma to separate elements?", infer_type(e)->tp_name); } default: @@ -3704,7 +3704,7 @@ check_subscripter(compiler *c, expr_ty e) case Lambda_kind: { location loc = LOC(e); return _PyCompile_Warn(c, loc, "'%.200s' object is not subscriptable; " - "perhaps you missed a comma?", + "did you miss a comma to separate elements?", infer_type(e)->tp_name); } default: @@ -3739,7 +3739,7 @@ check_index(compiler *c, expr_ty e, expr_ty s) location loc = LOC(e); return _PyCompile_Warn(c, loc, "%.200s indices must be integers " "or slices, not %.200s; " - "perhaps you missed a comma?", + "did you miss a comma to separate elements?", infer_type(e)->tp_name, index_type->tp_name); }