Fix DeprecationWarning while initializing Expression (#5739)

* Fix DeprecationWarning while initializing `Expression`

* Add news item

* Rename the news file to the branch name

* Fixing more ast related warnings
This commit is contained in:
Bala 2024-12-02 17:31:09 +05:30 committed by GitHub
parent 599f1c0f36
commit 0791372f30
Failed to generate hash of commit
2 changed files with 32 additions and 4 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fix DeprecationWarning while initializing Expression
**Security:**
* <news item>

View file

@ -738,7 +738,9 @@ class BaseParser:
def p_eval_input(self, p): def p_eval_input(self, p):
"""eval_input : testlist newlines_opt""" """eval_input : testlist newlines_opt"""
p1 = p[1] p1 = p[1]
p[0] = ast.Expression(body=p1, lineno=p1.lineno, col_offset=p1.col_offset) p[0] = ast.Expression(body=p1)
p[0].lineno = p1.lineno
p[0].col_offset = p1.col_offset
def p_func_call(self, p): def p_func_call(self, p):
"""func_call : LPAREN arglist_opt RPAREN""" """func_call : LPAREN arglist_opt RPAREN"""
@ -2155,7 +2157,8 @@ class BaseParser:
| minus_tok term | minus_tok term
""" """
p1 = p[1] p1 = p[1]
op = self._term_binops[p1.value](lineno=p1.lineno, col_offset=p1.lexpos) op = self._term_binops[p1.value]()
op.lineno, op.col_offset = p1.lineno, p1.lexpos
p[0] = [op, p[2]] p[0] = [op, p[2]]
def p_term(self, p): def p_term(self, p):
@ -2194,7 +2197,9 @@ class BaseParser:
f"operation {p1!r} not supported", f"operation {p1!r} not supported",
self.currloc(lineno=p.lineno, column=p.lexpos), self.currloc(lineno=p.lineno, column=p.lexpos),
) )
p[0] = [op(lineno=p1.lineno, col_offset=p1.lexpos), p[2]] op_node = op()
op_node.lineno, op_node.col_offset = p1.lineno, p1.lexpos
p[0] = [op_node, p[2]]
_factor_ops = {"+": ast.UAdd, "-": ast.USub, "~": ast.Invert} _factor_ops = {"+": ast.UAdd, "-": ast.USub, "~": ast.Invert}
@ -3047,7 +3052,7 @@ class BaseParser:
else: else:
targ = ensure_has_elts(targs) targ = ensure_has_elts(targs)
store_ctx(targ) store_ctx(targ)
comp = ast.comprehension(target=targ, iter=it, ifs=[]) comp = ast.comprehension(target=targ, iter=it, ifs=[], is_async=0)
comps = [comp] comps = [comp]
p0 = {"comps": comps} p0 = {"comps": comps}
if p5 is not None: if p5 is not None: