diff --git a/lib/astunparse/unparser.py b/lib/astunparse/unparser.py index 0ef6fd8..829835d 100644 --- a/lib/astunparse/unparser.py +++ b/lib/astunparse/unparser.py @@ -708,7 +708,10 @@ def _Attribute(self,t): # Special case: 3.__abs__() is a syntax error, so if t.value # is an integer literal then we need to either parenthesize # it or add an extra space to get 3 .__abs__(). - if isinstance(t.value, getattr(ast, 'Constant', getattr(ast, 'Num', None))) and isinstance(t.value.n, int): + ast_Num = getattr(ast, 'Num', None) + ast_Constant = getattr(ast, 'Constant', None) + if ((ast_Num and isinstance(t.value, ast_Num) and isinstance(t.value.n, int)) + or (ast_Constant and isinstance(t.value, ast_Constant) and isinstance(t.value.value, int))): self.write(" ") self.write(".") self.write(t.attr) diff --git a/tests/common.py b/tests/common.py index 95b9755..c8db903 100644 --- a/tests/common.py +++ b/tests/common.py @@ -215,7 +215,6 @@ def test_unary_parens(self): self.check_roundtrip("not True or False") self.check_roundtrip("True or not False") - @unittest.skipUnless(sys.version_info < (3, 6), "Only works for Python < 3.6") def test_integer_parens(self): self.check_roundtrip("3 .__abs__()")