From 728fcdaab312020fe3ebea40e942f23ee620ed6c Mon Sep 17 00:00:00 2001 From: Charles Brunet Date: Thu, 14 Sep 2023 15:20:33 -0400 Subject: [PATCH] simplify astprinter by using operator value --- mesonbuild/ast/printer.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py index 736cf8c30..004a64953 100644 --- a/mesonbuild/ast/printer.py +++ b/mesonbuild/ast/printer.py @@ -11,13 +11,6 @@ from .visitor import AstVisitor, FullAstVisitor import re import typing as T -arithmic_map = { - 'add': '+', - 'sub': '-', - 'mod': '%', - 'mul': '*', - 'div': '/' -} class AstPrinter(AstVisitor): def __init__(self, indent: int = 2, arg_newline_cutoff: int = 5, update_ast_line_nos: bool = False): @@ -126,7 +119,7 @@ class AstPrinter(AstVisitor): def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None: node.left.accept(self) - self.append_padded(arithmic_map[node.operation], node) + self.append_padded(node.operator.value, node) node.lineno = self.curr_line or node.lineno node.right.accept(self) @@ -379,7 +372,7 @@ class AstJSONPrinter(AstVisitor): def visit_ArithmeticNode(self, node: mparser.ArithmeticNode) -> None: self._accept('left', node.left) self._accept('right', node.right) - self.current['op'] = arithmic_map[node.operation] + self.current['op'] = node.operator.value self.setbase(node) def visit_NotNode(self, node: mparser.NotNode) -> None: