diff options
| -rw-r--r-- | astroid/as_string.py | 3 | ||||
| -rw-r--r-- | tests/unittest_inference.py | 23 |
2 files changed, 26 insertions, 0 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py index 57049141..6b20f46c 100644 --- a/astroid/as_string.py +++ b/astroid/as_string.py @@ -544,6 +544,9 @@ class AsStringVisitor: def visit_uninferable(self, node): return str(node) + def visit_property(self, node): + return node.function.accept(self) + class AsStringVisitor3(AsStringVisitor): """AsStringVisitor3 overwrites some AsStringVisitor methods""" diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index 4dc785ab..751a4586 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -24,6 +24,7 @@ """ # pylint: disable=too-many-lines import platform +import textwrap from functools import partial import unittest from unittest.mock import patch @@ -5479,6 +5480,28 @@ def test_property_inference(): assert isinstance(inferred, nodes.FunctionDef) +def test_property_as_string(): + code = """ + class A: + @property + def test(self): + return 42 + + A.test #@ + """ + node = extract_node(code) + inferred = next(node.infer()) + assert isinstance(inferred, objects.Property) + property_body = textwrap.dedent( + """ + @property + def test(self): + return 42 + """ + ) + assert inferred.as_string().strip() == property_body.strip() + + def test_property_callable_inference(): code = """ class A: |
