mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
bpo-34013: Don't consider a grouped expression when reporting legacy print syntax errors (GH-27521)
(cherry picked from commit 208a7e957b
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
76903ff9ce
commit
35035bc35a
3 changed files with 17 additions and 6 deletions
|
@ -849,7 +849,7 @@ expression_without_invalid[expr_ty]:
|
||||||
| disjunction
|
| disjunction
|
||||||
| lambdef
|
| lambdef
|
||||||
invalid_legacy_expression:
|
invalid_legacy_expression:
|
||||||
| a=NAME b=star_expressions {
|
| a=NAME !'(' b=star_expressions {
|
||||||
_PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b,
|
_PyPegen_check_legacy_stmt(p, a) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b,
|
||||||
"Missing parentheses in call to '%U'. Did you mean %U(...)?", a->v.Name.id, a->v.Name.id) : NULL}
|
"Missing parentheses in call to '%U'. Did you mean %U(...)?", a->v.Name.id, a->v.Name.id) : NULL}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,15 @@ class ExceptionTests(unittest.TestCase):
|
||||||
s = 'exec f(a+b,c)'
|
s = 'exec f(a+b,c)'
|
||||||
ckmsg(s, "Missing parentheses in call to 'exec'. Did you mean exec(...)?")
|
ckmsg(s, "Missing parentheses in call to 'exec'. Did you mean exec(...)?")
|
||||||
|
|
||||||
|
# Check that we don't incorrectly identify '(...)' as an expression to the right
|
||||||
|
# of 'print'
|
||||||
|
|
||||||
|
s = 'print (a+b,c) $ 42'
|
||||||
|
ckmsg(s, "invalid syntax")
|
||||||
|
|
||||||
|
s = 'exec (a+b,c) $ 42'
|
||||||
|
ckmsg(s, "invalid syntax")
|
||||||
|
|
||||||
# should not apply to subclasses, see issue #31161
|
# should not apply to subclasses, see issue #31161
|
||||||
s = '''if True:\nprint "No indent"'''
|
s = '''if True:\nprint "No indent"'''
|
||||||
ckmsg(s, "expected an indented block after 'if' statement on line 1", IndentationError)
|
ckmsg(s, "expected an indented block after 'if' statement on line 1", IndentationError)
|
||||||
|
|
|
@ -18180,7 +18180,7 @@ expression_without_invalid_rule(Parser *p)
|
||||||
return _res;
|
return _res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalid_legacy_expression: NAME star_expressions
|
// invalid_legacy_expression: NAME !'(' star_expressions
|
||||||
static void *
|
static void *
|
||||||
invalid_legacy_expression_rule(Parser *p)
|
invalid_legacy_expression_rule(Parser *p)
|
||||||
{
|
{
|
||||||
|
@ -18191,21 +18191,23 @@ invalid_legacy_expression_rule(Parser *p)
|
||||||
}
|
}
|
||||||
void * _res = NULL;
|
void * _res = NULL;
|
||||||
int _mark = p->mark;
|
int _mark = p->mark;
|
||||||
{ // NAME star_expressions
|
{ // NAME !'(' star_expressions
|
||||||
if (p->error_indicator) {
|
if (p->error_indicator) {
|
||||||
D(p->level--);
|
D(p->level--);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
D(fprintf(stderr, "%*c> invalid_legacy_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME star_expressions"));
|
D(fprintf(stderr, "%*c> invalid_legacy_expression[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "NAME !'(' star_expressions"));
|
||||||
expr_ty a;
|
expr_ty a;
|
||||||
expr_ty b;
|
expr_ty b;
|
||||||
if (
|
if (
|
||||||
(a = _PyPegen_name_token(p)) // NAME
|
(a = _PyPegen_name_token(p)) // NAME
|
||||||
&&
|
&&
|
||||||
|
_PyPegen_lookahead_with_int(0, _PyPegen_expect_token, p, 7) // token='('
|
||||||
|
&&
|
||||||
(b = star_expressions_rule(p)) // star_expressions
|
(b = star_expressions_rule(p)) // star_expressions
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
D(fprintf(stderr, "%*c+ invalid_legacy_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME star_expressions"));
|
D(fprintf(stderr, "%*c+ invalid_legacy_expression[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "NAME !'(' star_expressions"));
|
||||||
_res = _PyPegen_check_legacy_stmt ( p , a ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "Missing parentheses in call to '%U'. Did you mean %U(...)?" , a -> v . Name . id , a -> v . Name . id ) : NULL;
|
_res = _PyPegen_check_legacy_stmt ( p , a ) ? RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , b , "Missing parentheses in call to '%U'. Did you mean %U(...)?" , a -> v . Name . id , a -> v . Name . id ) : NULL;
|
||||||
if (_res == NULL && PyErr_Occurred()) {
|
if (_res == NULL && PyErr_Occurred()) {
|
||||||
p->error_indicator = 1;
|
p->error_indicator = 1;
|
||||||
|
@ -18216,7 +18218,7 @@ invalid_legacy_expression_rule(Parser *p)
|
||||||
}
|
}
|
||||||
p->mark = _mark;
|
p->mark = _mark;
|
||||||
D(fprintf(stderr, "%*c%s invalid_legacy_expression[%d-%d]: %s failed!\n", p->level, ' ',
|
D(fprintf(stderr, "%*c%s invalid_legacy_expression[%d-%d]: %s failed!\n", p->level, ' ',
|
||||||
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME star_expressions"));
|
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "NAME !'(' star_expressions"));
|
||||||
}
|
}
|
||||||
_res = NULL;
|
_res = NULL;
|
||||||
done:
|
done:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue