From dcde484a63e89a761e4506479681890f395f3d11 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 18 Jun 2020 17:20:17 +0200 Subject: [PATCH 1/2] Usual isinstance for mypy --- relational/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/relational/parser.py b/relational/parser.py index 1015dbf..65112d9 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -125,10 +125,10 @@ class Node: for i in range(level): r += ' ' r += self.name - if self.name in b_operators: + if self.name in b_operators and isinstance(self, Binary): r += self.left.printtree(level + 1) r += self.right.printtree(level + 1) - elif self.name in u_operators: + elif self.name in u_operators and isinstance(self, Unary): r += '\t%s\n' % self.prop r += self.child.printtree(level + 1) return '\n' + r From a74c17f323af60d488ec27cb215a5ae127ba3fd5 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Thu, 18 Jun 2020 17:24:45 +0200 Subject: [PATCH 2/2] More pythonic code --- relational/parser.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/relational/parser.py b/relational/parser.py index 65112d9..89862d0 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -121,10 +121,7 @@ class Node: def printtree(self, level: int = 0) -> str: '''returns a representation of the tree using indentation''' - r = '' - for i in range(level): - r += ' ' - r += self.name + r = ' ' * level + self.name if self.name in b_operators and isinstance(self, Binary): r += self.left.printtree(level + 1) r += self.right.printtree(level + 1)