diff --git a/astmonkey/tests/test_visitors.py b/astmonkey/tests/test_visitors.py index d060646..12ddec8 100644 --- a/astmonkey/tests/test_visitors.py +++ b/astmonkey/tests/test_visitors.py @@ -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 diff --git a/astmonkey/visitors.py b/astmonkey/visitors.py index 6393c10..35d7430 100644 --- a/astmonkey/visitors.py +++ b/astmonkey/visitors.py @@ -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): @@ -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):