From 5d2347443b199bef61766dd13e2758aca5234b97 Mon Sep 17 00:00:00 2001 From: David Bieber Date: Fri, 23 Feb 2018 15:43:51 -0800 Subject: [PATCH] Use __class__.__name__ for boolops loopup cmpops, binops, and unops already used this technique, but boolops did not. The reason this technique is preferred to using __class__ for the lookup is that when working with e.g. gast (a cross version compatible AST) the exact type match required by the __class__ lookup fails (since gast.And != ast.And), whereas the name based lookup works fine. --- lib/astunparse/unparser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/astunparse/unparser.py b/lib/astunparse/unparser.py index 767412c..15a19b9 100644 --- a/lib/astunparse/unparser.py +++ b/lib/astunparse/unparser.py @@ -642,10 +642,10 @@ def _Compare(self, t): self.dispatch(e) self.write(")") - boolops = {ast.And: 'and', ast.Or: 'or'} + boolops = {'And': 'and', 'Or': 'or'} def _BoolOp(self, t): self.write("(") - s = " %s " % self.boolops[t.op.__class__] + s = " %s " % self.boolops[t.op.__class__.__name__] interleave(lambda: self.write(s), self.dispatch, t.values) self.write(")")