-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-140764: Make "missed comma" syntax warning less cryptic #140893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1520,7 +1520,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 sequence elements\?' | ||||||
| check('[(1, 2) (3, 4)]') | ||||||
| check('[(x, y) (3, 4)]') | ||||||
| check('[[1, 2] (3, 4)]') | ||||||
|
|
@@ -1543,7 +1543,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 sequence elements\?' | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| check('[{1, 2} [i, j]]') | ||||||
| check('[{i for i in range(5)} [i, j]]') | ||||||
| check('[(i for i in range(5)) [i, j]]') | ||||||
|
|
@@ -1557,7 +1557,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 sequence elements\?' | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| check('[(1, 2) [i, j]]') | ||||||
| check('[(x, y) [i, j]]') | ||||||
| check('[[1, 2] [i, j]]') | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| Improve syntax warning messages for missing commas in sequences. The messages now say "did you miss a comma to separate sequence elements?" instead of "perhaps you missed a comma?". | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3650,7 +3650,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 sequence elements?", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| infer_type(e)->tp_name); | ||||||
| } | ||||||
| default: | ||||||
|
|
@@ -3681,7 +3681,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 sequence elements?", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| infer_type(e)->tp_name); | ||||||
| } | ||||||
| default: | ||||||
|
|
@@ -3716,7 +3716,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 sequence elements?", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| infer_type(e)->tp_name, | ||||||
| index_type->tp_name); | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.