From 0791372f30ac89bbf5cb2078e47f842598d5206d Mon Sep 17 00:00:00 2001 From: Bala Date: Mon, 2 Dec 2024 17:31:09 +0530 Subject: [PATCH] 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 --- news/fix_warning_Expression.rst | 23 +++++++++++++++++++++++ xonsh/parsers/base.py | 13 +++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 news/fix_warning_Expression.rst diff --git a/news/fix_warning_Expression.rst b/news/fix_warning_Expression.rst new file mode 100644 index 000000000..e90daaeb9 --- /dev/null +++ b/news/fix_warning_Expression.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fix DeprecationWarning while initializing Expression + +**Security:** + +* diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py index c1223cf83..239926d03 100644 --- a/xonsh/parsers/base.py +++ b/xonsh/parsers/base.py @@ -738,7 +738,9 @@ class BaseParser: def p_eval_input(self, p): """eval_input : testlist newlines_opt""" 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): """func_call : LPAREN arglist_opt RPAREN""" @@ -2155,7 +2157,8 @@ class BaseParser: | minus_tok term """ 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]] def p_term(self, p): @@ -2194,7 +2197,9 @@ class BaseParser: f"operation {p1!r} not supported", 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} @@ -3047,7 +3052,7 @@ class BaseParser: else: targ = ensure_has_elts(targs) store_ctx(targ) - comp = ast.comprehension(target=targ, iter=it, ifs=[]) + comp = ast.comprehension(target=targ, iter=it, ifs=[], is_async=0) comps = [comp] p0 = {"comps": comps} if p5 is not None: