From 7052b2c432c8994f1ba1a7ce4d424c4360e3372e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 9 Sep 2020 12:55:09 -0700 Subject: [PATCH] Fix __str__ in case self.token is not a string. --- voussoirkit/expressionmatch.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/voussoirkit/expressionmatch.py b/voussoirkit/expressionmatch.py index 1165ed9..d5e351f 100644 --- a/voussoirkit/expressionmatch.py +++ b/voussoirkit/expressionmatch.py @@ -59,8 +59,10 @@ class ExpressionTree: if self.token is None: return '""' - if self.token not in OPERATORS: - t = self.token + self_token = str(self.token) + + if self_token not in OPERATORS: + t = self_token t = t.replace('"', '\\"') t = t.replace('(', '\\(') t = t.replace(')', '\\)') @@ -72,8 +74,8 @@ class ExpressionTree: child = self.children[0] childstring = str(child) if child.token in OPERATORS: - return f'{self.token}({childstring})' - return f'{self.token} {childstring}' + return f'{self_token}({childstring})' + return f'{self_token} {childstring}' children = [] for child in self.children: @@ -83,9 +85,9 @@ class ExpressionTree: children.append(childstring) if len(children) == 1: - return f'{self.token} {children[0]}' + return f'{self_token} {children[0]}' - s = f' {self.token} ' + s = f' {self_token} ' s = s.join(children) return s