bpo-34013: Generalize the invalid legacy statement error message (GH-… · python/cpython@6948964 (original) (raw)
File tree
6 files changed
lines changed
- Misc/NEWS.d/next/Core and Builtins
6 files changed
lines changed
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -847,10 +847,15 @@ expression_without_invalid[expr_ty]: | |||
847 | 847 | | a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) } | |
848 | 848 | | disjunction | |
849 | 849 | | lambdef | |
850 | +invalid_legacy_expression: | ||
851 | + | a=NAME b=expression_without_invalid { | ||
852 | + _PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "Missing parentheses in call to '%U'.", a->v.Name.id) : NULL} | ||
853 | + | ||
850 | 854 | invalid_expression: | |
855 | + | invalid_legacy_expression | ||
851 | 856 | # !(NAME STRING) is not matched so we don't show this error with some invalid string prefixes like: kf"dsfsdf" | |
852 | 857 | # Soft keywords need to also be ignored because they can be parsed as NAME NAME | |
853 | - | !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid { | |
858 | + | !(NAME STRING | SOFT_KEYWORD) a=disjunction b=expression_without_invalid { | |
854 | 859 | RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "invalid syntax. Perhaps you forgot a comma?") } | |
855 | 860 | ||
856 | 861 | invalid_named_expression: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -175,9 +175,15 @@ def ckmsg(src, msg, exception=SyntaxError): | ||
175 | 175 | ckmsg(s, "Missing parentheses in call to 'print'. " |
176 | 176 | "Did you mean print(\"old style\", end=\" \")?") |
177 | 177 | |
178 | +s = 'print f(a+b,c)' | |
179 | +ckmsg(s, "Missing parentheses in call to 'print'.") | |
180 | + | |
178 | 181 | s = '''exec "old style"''' |
179 | 182 | ckmsg(s, "Missing parentheses in call to 'exec'") |
180 | 183 | |
184 | +s = 'exec f(a+b,c)' | |
185 | +ckmsg(s, "Missing parentheses in call to 'exec'.") | |
186 | + | |
181 | 187 | # should not apply to subclasses, see issue #31161 |
182 | 188 | s = '''if True:\nprint "No indent"''' |
183 | 189 | ckmsg(s, "expected an indented block after 'if' statement on line 1", IndentationError) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | +Generalize the invalid legacy statement custom error message (like the one | |
2 | +generated when "print" is called without parentheses) to include more | |
3 | +generic expressions. Patch by Pablo Galindo |