Skip to content

Commit ce857ce

Browse files
committed
fix: ast deprecation with py3.13
1 parent 7acbe28 commit ce857ce

File tree

10 files changed

+127
-55
lines changed

10 files changed

+127
-55
lines changed

peg_parser/parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,8 +1683,8 @@ def mapping_pattern(self) -> Any | None:
16831683
and (self.expect("}"))
16841684
):
16851685
return ast.MatchMapping(
1686-
keys=[k for (k, _) in items],
1687-
patterns=[p for (_, p) in items],
1686+
keys=[k for k, _ in items],
1687+
patterns=[p for _, p in items],
16881688
rest=rest,
16891689
**self.span(_lnum, _col),
16901690
)
@@ -1696,8 +1696,8 @@ def mapping_pattern(self) -> Any | None:
16961696
and (self.expect("}"))
16971697
):
16981698
return ast.MatchMapping(
1699-
keys=[k for (k, _) in items],
1700-
patterns=[p for (_, p) in items],
1699+
keys=[k for k, _ in items],
1700+
patterns=[p for _, p in items],
17011701
rest=None,
17021702
**self.span(_lnum, _col),
17031703
)
@@ -1762,8 +1762,8 @@ def class_pattern(self) -> ast.MatchClass | None:
17621762
return ast.MatchClass(
17631763
cls=cls,
17641764
patterns=[],
1765-
kwd_attrs=[k for (k, _) in keywords],
1766-
kwd_patterns=[p for (_, p) in keywords],
1765+
kwd_attrs=[k for k, _ in keywords],
1766+
kwd_patterns=[p for _, p in keywords],
17671767
**self.span(_lnum, _col),
17681768
)
17691769
self._reset(mark)
@@ -1779,8 +1779,8 @@ def class_pattern(self) -> ast.MatchClass | None:
17791779
return ast.MatchClass(
17801780
cls=cls,
17811781
patterns=patterns,
1782-
kwd_attrs=[k for (k, _) in keywords],
1783-
kwd_patterns=[p for (_, p) in keywords],
1782+
kwd_attrs=[k for k, _ in keywords],
1783+
kwd_patterns=[p for _, p in keywords],
17841784
**self.span(_lnum, _col),
17851785
)
17861786
self._reset(mark)
@@ -4552,10 +4552,10 @@ def invalid_while_stmt(self) -> None:
45524552

45534553
@memoize
45544554
def invalid_for_stmt(self) -> None:
4555-
# invalid_for_stmt: ASYNC? 'for' star_targets 'in' star_expressions NEWLINE | 'async'? 'for' star_targets 'in' star_expressions ':' NEWLINE !INDENT
4555+
# invalid_for_stmt: 'async'? 'for' star_targets 'in' star_expressions NEWLINE | 'async'? 'for' star_targets 'in' star_expressions ':' NEWLINE !INDENT
45564556
mark = self._mark()
45574557
if (
4558-
(self.token("ASYNC"),)
4558+
(self.expect("async"),)
45594559
and (self.expect("for"))
45604560
and (self.star_targets())
45614561
and (self.expect("in"))

peg_parser/subheader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def xonsh_call(name: str, *args: Node, **locs: int) -> ast.Call:
242242
func=load_attribute_chain(name, **locs),
243243
args=list(args), # type: ignore
244244
keywords=[],
245-
starargs=None,
246-
kwargs=None,
245+
# starargs=None,
246+
# kwargs=None,
247247
**locs,
248248
)
249249

ply_parser/parsers/base.py

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,10 @@ def p_newlines(self, p):
699699
def p_eval_input(self, p):
700700
"""eval_input : testlist newlines_opt"""
701701
p1 = p[1]
702-
p[0] = ast.Expression(body=p1, lineno=p1.lineno, col_offset=p1.col_offset)
702+
p[0] = ast.Expression(
703+
body=p1,
704+
# lineno=p1.lineno, col_offset=p1.col_offset
705+
)
703706

704707
def p_func_call(self, p):
705708
"""func_call : LPAREN arglist_opt RPAREN"""
@@ -1290,7 +1293,12 @@ def p_del_stmt(self, p):
12901293
p2 = p[2]
12911294
for targ in p2:
12921295
del_ctx(targ)
1293-
p0 = ast.Delete(targets=p2, ctx=ast.Del(), lineno=p1.lineno, col_offset=p1.lexpos)
1296+
p0 = ast.Delete(
1297+
targets=p2,
1298+
# ctx=ast.Del(),
1299+
lineno=p1.lineno,
1300+
col_offset=p1.lexpos,
1301+
)
12941302
p[0] = p0
12951303

12961304
def p_pass_stmt(self, p):
@@ -2028,7 +2036,9 @@ def p_pm_term(self, p):
20282036
| minus_tok term
20292037
"""
20302038
p1 = p[1]
2031-
op = self._term_binops[p1.value](lineno=p1.lineno, col_offset=p1.lexpos)
2039+
op = self._term_binops[p1.value](
2040+
# lineno=p1.lineno, col_offset=p1.lexpos
2041+
)
20322042
p[0] = [op, p[2]]
20332043

20342044
def p_term(self, p):
@@ -2063,7 +2073,12 @@ def p_op_factor(self, p):
20632073
f"operation {p1!r} not supported",
20642074
self.currloc(lineno=p.lineno, column=p.lexpos),
20652075
)
2066-
p[0] = [op(lineno=p1.lineno, col_offset=p1.lexpos), p[2]]
2076+
p[0] = [
2077+
op(
2078+
# lineno=p1.lineno, col_offset=p1.lexpos
2079+
),
2080+
p[2],
2081+
]
20672082

20682083
_factor_ops = {"+": ast.UAdd, "-": ast.USub, "~": ast.Invert}
20692084

@@ -2236,7 +2251,7 @@ def p_atom_lbrace(self, p):
22362251
p0 = ast.Dict(
22372252
keys=[],
22382253
values=[],
2239-
ctx=ast.Load(),
2254+
# ctx=ast.Load(),
22402255
lineno=self.lineno,
22412256
col_offset=self.col,
22422257
)
@@ -2402,8 +2417,13 @@ def p_string_literal(self, p):
24022417
else:
24032418
s = ast.literal_eval(p1.value)
24042419
# is_bytes = "b" in prefix
2405-
is_raw = "r" in prefix
2406-
p[0] = ast.const(s, lineno=p1.lineno, col_offset=p1.lexpos, is_raw=is_raw)
2420+
# is_raw = "r" in prefix
2421+
p[0] = ast.const(
2422+
s,
2423+
lineno=p1.lineno,
2424+
col_offset=p1.lexpos,
2425+
# is_raw=is_raw
2426+
)
24072427

24082428
def p_string_literal_list(self, p):
24092429
"""
@@ -2765,7 +2785,13 @@ def p_dictorsetmaker_t6(self, p):
27652785
keys.append(k)
27662786
vals.append(v)
27672787
lineno, col = lopen_loc(p1)
2768-
p[0] = ast.Dict(keys=keys, values=vals, ctx=ast.Load(), lineno=lineno, col_offset=col)
2788+
p[0] = ast.Dict(
2789+
keys=keys,
2790+
values=vals,
2791+
# ctx=ast.Load(),
2792+
lineno=lineno,
2793+
col_offset=col,
2794+
)
27692795

27702796
def p_dictorsetmaker_i4(self, p):
27712797
"""dictorsetmaker : item comma_item_list comma_opt"""
@@ -2776,36 +2802,69 @@ def p_dictorsetmaker_i4(self, p):
27762802
keys.append(k)
27772803
vals.append(v)
27782804
lineno, col = lopen_loc(p1[0] or p1[1])
2779-
p[0] = ast.Dict(keys=keys, values=vals, ctx=ast.Load(), lineno=lineno, col_offset=col)
2805+
p[0] = ast.Dict(
2806+
keys=keys,
2807+
values=vals,
2808+
# ctx=ast.Load(),
2809+
lineno=lineno,
2810+
col_offset=col,
2811+
)
27802812

27812813
def p_dictorsetmaker_t4_dict(self, p):
27822814
"""dictorsetmaker : test COLON testlist"""
27832815
keys = [p[1]]
27842816
vals = self._list_or_elts_if_not_real_tuple(p[3])
27852817
lineno, col = lopen_loc(p[1])
2786-
p[0] = ast.Dict(keys=keys, values=vals, ctx=ast.Load(), lineno=lineno, col_offset=col)
2818+
p[0] = ast.Dict(
2819+
keys=keys,
2820+
values=vals,
2821+
# ctx=ast.Load(),
2822+
lineno=lineno,
2823+
col_offset=col,
2824+
)
27872825

27882826
def p_dictorsetmaker_item_comma(self, p):
27892827
"""dictorsetmaker : item comma_opt"""
27902828
p1 = p[1]
27912829
keys = [p1[0]]
27922830
vals = [p1[1]]
27932831
lineno, col = lopen_loc(p1[0] or p1[1])
2794-
p[0] = ast.Dict(keys=keys, values=vals, ctx=ast.Load(), lineno=lineno, col_offset=col)
2832+
p[0] = ast.Dict(
2833+
keys=keys,
2834+
values=vals,
2835+
# ctx=ast.Load(),
2836+
lineno=lineno,
2837+
col_offset=col,
2838+
)
27952839

27962840
def p_dictorsetmaker_t4_set(self, p):
27972841
"""dictorsetmaker : test_or_star_expr comma_test_or_star_expr_list comma_opt"""
2798-
p[0] = ast.Set(elts=[p[1]] + p[2], ctx=ast.Load(), lineno=self.lineno, col_offset=self.col)
2842+
p[0] = ast.Set(
2843+
elts=[p[1]] + p[2],
2844+
# ctx=ast.Load(),
2845+
lineno=self.lineno,
2846+
col_offset=self.col,
2847+
)
27992848

28002849
def p_dictorsetmaker_test_comma(self, p):
28012850
"""dictorsetmaker : test_or_star_expr comma_opt"""
28022851
elts = self._list_or_elts_if_not_real_tuple(p[1])
2803-
p[0] = ast.Set(elts=elts, ctx=ast.Load(), lineno=self.lineno, col_offset=self.col)
2852+
p[0] = ast.Set(
2853+
elts=elts,
2854+
# ctx=ast.Load(),
2855+
lineno=self.lineno,
2856+
col_offset=self.col,
2857+
)
28042858

28052859
def p_dictorsetmaker_testlist(self, p):
28062860
"""dictorsetmaker : testlist"""
28072861
elts = self._list_or_elts_if_not_real_tuple(p[1])
2808-
p[0] = ast.Set(elts=elts, ctx=ast.Load(), lineno=self.lineno, col_offset=self.col)
2862+
p[0] = ast.Set(
2863+
elts=elts,
2864+
# ctx=ast.Load(),
2865+
lineno=self.lineno,
2866+
col_offset=self.col,
2867+
)
28092868

28102869
def p_dictorsetmaker_comp(self, p):
28112870
"""
@@ -2859,7 +2918,7 @@ def p_comp_for(self, p):
28592918
else:
28602919
targ = ensure_has_elts(targs)
28612920
store_ctx(targ)
2862-
comp = ast.comprehension(target=targ, iter=it, ifs=[])
2921+
comp = ast.comprehension(target=targ, iter=it, ifs=[], is_async=0)
28632922
comps = [comp]
28642923
p0 = {"comps": comps}
28652924
if p5 is not None:

ply_parser/parsers/v310.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def p_case_block(self, p):
7777
loc = self.get_line_cols(p, 1)
7878
match list(p):
7979
case [_, _, pattern, _, suite]:
80-
p[0] = ast.match_case(pattern=pattern, body=suite, **loc)
80+
p[0] = ast.match_case(
81+
pattern=pattern,
82+
body=suite,
83+
# **loc
84+
)
8185
case [_, _, pattern, _, guard, _, suite]:
8286
p[0] = ast.match_case(pattern=pattern, body=suite, guard=guard, **loc)
8387
case _:

ply_parser/parsers/v36.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ def p_atom_expr_await(self, p):
4545
"""atom_expr : await_tok atom trailer_list_opt"""
4646
p0 = self.apply_trailers(p[2], p[3])
4747
p1 = p[1]
48-
p0 = ast.Await(value=p0, ctx=ast.Load(), lineno=p1.lineno, col_offset=p1.lexpos)
48+
p0 = ast.Await(
49+
value=p0,
50+
# ctx=ast.Load(),
51+
lineno=p1.lineno,
52+
col_offset=p1.lexpos,
53+
)
4954
p[0] = p0
5055

5156
def p_async_stmt(self, p):

0 commit comments

Comments
 (0)