Skip to content

Commit

Permalink
Fix removal of parentheses around NamedConstants in SourceGeneratorNo…
Browse files Browse the repository at this point in the history
…deVisitor for Python > 3.3
  • Loading branch information
phihos committed Nov 11, 2018
1 parent 49ad141 commit 0d5a97a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions astmonkey/tests/test_visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class TestSourceGeneratorNodeVisitor(object):
'y * (z if z > 1 else 1)',
'if x < y == z < x:' + EOL + INDENT + PASS,
'if (x < y) == (z < x):' + EOL + INDENT + PASS,
'if not False:' + EOL + INDENT + PASS,
'if x:' + EOL + INDENT + PASS + EOL + EOL + 'elif x:' + EOL + INDENT + PASS, # Double EOL

# while
Expand Down
4 changes: 2 additions & 2 deletions astmonkey/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def visit_UnaryOp(self, node):
self.write(' ')

with self.inside('(', ')', cond=(not isinstance(node.operand, (ast.Name, ast.Num))
and not self._is_named_constant(node))):
and not self._is_named_constant(node.operand))):
self.visit(node.operand)

def visit_Subscript(self, node):
Expand Down Expand Up @@ -836,7 +836,7 @@ def with_body(self, node, prefixes=[]):

@staticmethod
def _is_named_constant(node):
return isinstance(node, ast.Expr) and hasattr(node, value) and isinstance(node.value, ast.Name)
return isinstance(node, ast.Expr) and hasattr(node, 'value') and isinstance(node.value, ast.Name)


class SourceGeneratorNodeVisitorPython26(BaseSourceGeneratorNodeVisitor):
Expand Down

0 comments on commit 0d5a97a

Please sign in to comment.