Skip to content

Commit 6f01d08

Browse files
committed
Address feedback from review
1 parent ee7bc89 commit 6f01d08

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Grammar/python.gram

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ t_atom[expr_ty]:
781781
invalid_arguments:
782782
| a=args ',' '*' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable argument unpacking follows keyword argument unpacking") }
783783
| a=expression b=for_if_clauses ',' [args | expression for_if_clauses] {
784-
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, asdl_seq_GET(b, b->size-1)->target, "Generator expression must be parenthesized") }
784+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, PyPegen_last_item(b, comprehension_ty)->target, "Generator expression must be parenthesized") }
785785
| a=args for_if_clauses { _PyPegen_nonparen_genexp_in_call(p, a) }
786786
| args ',' a=expression b=for_if_clauses {
787787
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, asdl_seq_GET(b, b->size-1)->target, "Generator expression must be parenthesized") }
@@ -842,7 +842,7 @@ invalid_comprehension:
842842
| ('[' | '(' | '{') a=starred_expression for_if_clauses {
843843
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }
844844
| ('[' | '{') a=star_named_expression ',' b=star_named_expressions for_if_clauses {
845-
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, (expr_ty)_PyPegen_seq_last_item((asdl_seq*)b),
845+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, PyPegen_last_item(b, expr_ty),
846846
"did you forget parentheses around the comprehension target?") }
847847
| ('[' | '{') a=star_named_expression b=',' for_if_clauses {
848848
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "did you forget parentheses around the comprehension target?") }

Parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17521,7 +17521,7 @@ invalid_arguments_rule(Parser *p)
1752117521
)
1752217522
{
1752317523
D(fprintf(stderr, "%*c+ invalid_arguments[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "expression for_if_clauses ',' [args | expression for_if_clauses]"));
17524-
_res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , asdl_seq_GET ( b , b -> size - 1 ) -> target , "Generator expression must be parenthesized" );
17524+
_res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , PyPegen_last_item ( b , comprehension_ty ) -> target , "Generator expression must be parenthesized" );
1752517525
if (_res == NULL && PyErr_Occurred()) {
1752617526
p->error_indicator = 1;
1752717527
D(p->level--);
@@ -18329,7 +18329,7 @@ invalid_comprehension_rule(Parser *p)
1832918329
)
1833018330
{
1833118331
D(fprintf(stderr, "%*c+ invalid_comprehension[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "('[' | '{') star_named_expression ',' star_named_expressions for_if_clauses"));
18332-
_res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , ( expr_ty ) _PyPegen_seq_last_item ( ( asdl_seq * ) b ) , "did you forget parentheses around the comprehension target?" );
18332+
_res = RAISE_SYNTAX_ERROR_KNOWN_RANGE ( a , PyPegen_last_item ( b , expr_ty ) , "did you forget parentheses around the comprehension target?" );
1833318333
if (_res == NULL && PyErr_Occurred()) {
1833418334
p->error_indicator = 1;
1833518335
D(p->level--);

Parser/pegen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ void *_PyPegen_raise_error_known_location(Parser *p, PyObject *errtype,
140140
const char *errmsg, va_list va);
141141
void *_PyPegen_dummy_name(Parser *p, ...);
142142

143-
144143
void * _PyPegen_seq_last_item(asdl_seq *seq);
144+
#define PyPegen_last_item(seq, type) ((type)_PyPegen_seq_last_item((asdl_seq*)seq))
145145

146146
#define CURRENT_POS (-5)
147147

Python/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5480,7 +5480,7 @@ compiler_error(struct compiler *c, const char *format, ...)
54805480
Py_INCREF(Py_None);
54815481
loc = Py_None;
54825482
}
5483-
PyObject *args = Py_BuildValue("O(OiiOi)", msg, c->c_filename,
5483+
PyObject *args = Py_BuildValue("O(OiiOii)", msg, c->c_filename,
54845484
c->u->u_lineno, c->u->u_col_offset + 1, loc,
54855485
c->u->u_end_lineno, c->u->u_end_col_offset + 1);
54865486
Py_DECREF(msg);

0 commit comments

Comments
 (0)