Skip to content

Commit c111355

Browse files
authored
bpo-41826: Fix compiler warnings in test_peg_generator (GH-22455)
Co-authored-by: Skip Montanaro
1 parent 5230131 commit c111355

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Lib/test/test_peg_generator/test_c_parser.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run_test(self, grammar_source, test_source):
9090

9191
def test_c_parser(self) -> None:
9292
grammar_source = """
93-
start[mod_ty]: a=stmt* $ { Module(a, NULL, p->arena) }
93+
start[mod_ty]: a[asdl_stmt_seq*]=stmt* $ { Module(a, NULL, p->arena) }
9494
stmt[stmt_ty]: a=expr_stmt { a }
9595
expr_stmt[stmt_ty]: a=expression NEWLINE { _Py_Expr(a, EXTRA) }
9696
expression[expr_ty]: ( l=expression '+' r=term { _Py_BinOp(l, Add, r, EXTRA) }
@@ -232,7 +232,7 @@ def test_nasty_mutually_left_recursive(self) -> None:
232232
def test_return_stmt_noexpr_action(self) -> None:
233233
grammar_source = """
234234
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
235-
statements[asdl_seq*]: a=statement+ { a }
235+
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
236236
statement[stmt_ty]: simple_stmt
237237
simple_stmt[stmt_ty]: small_stmt
238238
small_stmt[stmt_ty]: return_stmt
@@ -246,7 +246,7 @@ def test_return_stmt_noexpr_action(self) -> None:
246246

247247
def test_gather_action_ast(self) -> None:
248248
grammar_source = """
249-
start[mod_ty]: a=';'.pass_stmt+ NEWLINE ENDMARKER { Module(a, NULL, p->arena) }
249+
start[mod_ty]: a[asdl_stmt_seq*]=';'.pass_stmt+ NEWLINE ENDMARKER { Module(a, NULL, p->arena) }
250250
pass_stmt[stmt_ty]: a='pass' { _Py_Pass(EXTRA)}
251251
"""
252252
test_source = """
@@ -258,7 +258,7 @@ def test_gather_action_ast(self) -> None:
258258
def test_pass_stmt_action(self) -> None:
259259
grammar_source = """
260260
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
261-
statements[asdl_seq*]: a=statement+ { a }
261+
statements[asdl_stmt_seq*]: a[asdl_stmt_seq*]=statement+ { a }
262262
statement[stmt_ty]: simple_stmt
263263
simple_stmt[stmt_ty]: small_stmt
264264
small_stmt[stmt_ty]: pass_stmt
@@ -273,10 +273,11 @@ def test_pass_stmt_action(self) -> None:
273273
def test_if_stmt_action(self) -> None:
274274
grammar_source = """
275275
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
276-
statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) }
277-
statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) } | simple_stmt
276+
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
277+
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) } | simple_stmt
278278
279-
simple_stmt[asdl_seq*]: a=small_stmt b=further_small_stmt* [';'] NEWLINE { _PyPegen_seq_insert_in_front(p, a, b) }
279+
simple_stmt[asdl_stmt_seq*]: a=small_stmt b=further_small_stmt* [';'] NEWLINE {
280+
(asdl_stmt_seq*)_PyPegen_seq_insert_in_front(p, a, b) }
280281
further_small_stmt[stmt_ty]: ';' a=small_stmt { a }
281282
282283
block: simple_stmt | NEWLINE INDENT a=statements DEDENT { a }
@@ -299,14 +300,14 @@ def test_if_stmt_action(self) -> None:
299300

300301
def test_same_name_different_types(self) -> None:
301302
grammar_source = """
302-
start[mod_ty]: a=import_from+ NEWLINE ENDMARKER { Module(a, NULL, p->arena)}
303+
start[mod_ty]: a[asdl_stmt_seq*]=import_from+ NEWLINE ENDMARKER { Module(a, NULL, p->arena)}
303304
import_from[stmt_ty]: ( a='from' !'import' c=simple_name 'import' d=import_as_names_from {
304305
_Py_ImportFrom(c->v.Name.id, d, 0, EXTRA) }
305306
| a='from' '.' 'import' c=import_as_names_from {
306307
_Py_ImportFrom(NULL, c, 1, EXTRA) }
307308
)
308309
simple_name[expr_ty]: NAME
309-
import_as_names_from[asdl_seq*]: a=','.import_as_name_from+ { a }
310+
import_as_names_from[asdl_alias_seq*]: a[asdl_alias_seq*]=','.import_as_name_from+ { a }
310311
import_as_name_from[alias_ty]: a=NAME 'as' b=NAME { _Py_alias(((expr_ty) a)->v.Name.id, ((expr_ty) b)->v.Name.id, p->arena) }
311312
"""
312313
test_source = """
@@ -320,12 +321,12 @@ def test_same_name_different_types(self) -> None:
320321
def test_with_stmt_with_paren(self) -> None:
321322
grammar_source = """
322323
start[mod_ty]: a=[statements] ENDMARKER { Module(a, NULL, p->arena) }
323-
statements[asdl_seq*]: a=statement+ { _PyPegen_seq_flatten(p, a) }
324-
statement[asdl_seq*]: a=compound_stmt { _PyPegen_singleton_seq(p, a) }
324+
statements[asdl_stmt_seq*]: a=statement+ { (asdl_stmt_seq*)_PyPegen_seq_flatten(p, a) }
325+
statement[asdl_stmt_seq*]: a=compound_stmt { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, a) }
325326
compound_stmt[stmt_ty]: with_stmt
326327
with_stmt[stmt_ty]: (
327-
a='with' '(' b=','.with_item+ ')' ':' c=block {
328-
_Py_With(b, _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
328+
a='with' '(' b[asdl_withitem_seq*]=','.with_item+ ')' ':' c=block {
329+
_Py_With(b, (asdl_stmt_seq*) _PyPegen_singleton_seq(p, c), NULL, EXTRA) }
329330
)
330331
with_item[withitem_ty]: (
331332
e=NAME o=['as' t=NAME { t }] { _Py_withitem(e, _PyPegen_set_expr_context(p, o, Store), p->arena) }
@@ -346,12 +347,12 @@ def test_with_stmt_with_paren(self) -> None:
346347
def test_ternary_operator(self) -> None:
347348
grammar_source = """
348349
start[mod_ty]: a=expr ENDMARKER { Module(a, NULL, p->arena) }
349-
expr[asdl_seq*]: a=listcomp NEWLINE { _PyPegen_singleton_seq(p, _Py_Expr(a, EXTRA)) }
350+
expr[asdl_stmt_seq*]: a=listcomp NEWLINE { (asdl_stmt_seq*)_PyPegen_singleton_seq(p, _Py_Expr(a, EXTRA)) }
350351
listcomp[expr_ty]: (
351352
a='[' b=NAME c=for_if_clauses d=']' { _Py_ListComp(b, c, EXTRA) }
352353
)
353-
for_if_clauses[asdl_seq*]: (
354-
a=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c=('if' z=NAME { z })*
354+
for_if_clauses[asdl_comprehension_seq*]: (
355+
a[asdl_comprehension_seq*]=(y=[ASYNC] 'for' a=NAME 'in' b=NAME c[asdl_expr_seq*]=('if' z=NAME { z })*
355356
{ _Py_comprehension(_Py_Name(((expr_ty) a)->v.Name.id, Store, EXTRA), b, c, (y == NULL) ? 0 : 1, p->arena) })+ { a }
356357
)
357358
"""

0 commit comments

Comments
 (0)