Skip to content

Commit 1d601e6

Browse files
authored
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.
1 parent c363330 commit 1d601e6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/astunparse/unparser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,10 @@ def _Compare(self, t):
620620
self.dispatch(e)
621621
self.write(")")
622622

623-
boolops = {ast.And: 'and', ast.Or: 'or'}
623+
boolops = {'And': 'and', 'Or': 'or'}
624624
def _BoolOp(self, t):
625625
self.write("(")
626-
s = " %s " % self.boolops[t.op.__class__]
626+
s = " %s " % self.boolops[t.op.__class__.__name__]
627627
interleave(lambda: self.write(s), self.dispatch, t.values)
628628
self.write(")")
629629

0 commit comments

Comments
 (0)