summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--astroid/as_string.py5
-rw-r--r--tests/unittest_nodes.py8
2 files changed, 12 insertions, 1 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py
index a19400ed..aa80567a 100644
--- a/astroid/as_string.py
+++ b/astroid/as_string.py
@@ -336,7 +336,10 @@ class AsStringVisitor:
def visit_attribute(self, node):
"""return an astroid.Getattr node as string"""
- return "%s.%s" % (self._precedence_parens(node, node.expr), node.attrname)
+ left = self._precedence_parens(node, node.expr)
+ if left.isdigit(): # TODO
+ left = "(%s)" % left
+ return "%s.%s" % (left, node.attrname)
def visit_global(self, node):
"""return an astroid.Global node as string"""
diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py
index 3d785c0f..fafd063d 100644
--- a/tests/unittest_nodes.py
+++ b/tests/unittest_nodes.py
@@ -200,6 +200,14 @@ if all[1] == bord[0:]:
ast = abuilder.string_build(code)
self.assertEqual(ast.as_string(), code)
+ def test_int_attribute(self):
+ code = """
+x = (-3).real
+y = (3).imag
+ """
+ ast = abuilder.string_build(code)
+ self.assertEqual(ast.as_string().strip(), code.strip())
+
def test_operator_precedence(self):
with open(resources.find("data/operator_precedence.py")) as f:
for code in f: