summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-17 18:03:21 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-17 18:03:21 +0300
commit04444f62d6828db538cc1b4a127407ca2886c22d (patch)
treeffe8935b5babb9c5a5e1fefecf445464c299993a
parentbc20fa60c0ec9cd9b63a14901d844f00c501a196 (diff)
downloadastroid-04444f62d6828db538cc1b4a127407ca2886c22d.tar.gz
Improve the inference of Getattr nodes when dealing with abstract properties from the abc module.
In astroid.bases.Instance._wrap_attr we had a detection code for properties, which basically inferred whatever a property returned, passing the results up the stack, to the igetattr() method. It handled only the builtin property but the new patch also handles abc.abstractproperty.
-rw-r--r--ChangeLog9
-rw-r--r--astroid/bases.py3
-rw-r--r--astroid/tests/unittest_inference.py16
3 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d8b5b44..3c7f633 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,15 @@ Change log for the astroid package (used to be astng)
classes without slots at all. This was changed in order
to better reflect what's actually happening.
+ * Improve the inference of Getattr nodes when dealing with
+ abstract properties from the abc module.
+
+ In astroid.bases.Instance._wrap_attr we had a detection
+ code for properties, which basically inferred whatever
+ a property returned, passing the results up the stack,
+ to the igetattr() method. It handled only the builtin property
+ but the new patch also handles abc.abstractproperty.
+
2015-03-14 -- 1.3.6
diff --git a/astroid/bases.py b/astroid/bases.py
index ee8ee1c..7de2c30 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -34,6 +34,7 @@ if sys.version_info >= (3, 0):
BUILTINS = 'builtins'
else:
BUILTINS = '__builtin__'
+PROPERTIES = {BUILTINS + '.property', 'abc.abstractproperty'}
class Proxy(object):
@@ -205,7 +206,7 @@ class Instance(Proxy):
"""wrap bound methods of attrs in a InstanceMethod proxies"""
for attr in attrs:
if isinstance(attr, UnboundMethod):
- if BUILTINS + '.property' in attr.decoratornames():
+ if PROPERTIES.intersection(attr.decoratornames()):
for infered in attr.infer_call_result(self, context):
yield infered
else:
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index 135681c..1ddba4e 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -121,6 +121,22 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
ast = test_utils.build_module(CODE, __name__)
+ def test_infer_abstract_property_return_values(self):
+ module = test_utils.build_module('''
+ import abc
+
+ class A(object):
+ @abc.abstractproperty
+ def test(self):
+ return 42
+
+ a = A()
+ x = a.test
+ ''')
+ inferred = next(module['x'].infer())
+ self.assertIsInstance(inferred, nodes.Const)
+ self.assertEqual(inferred.value, 42)
+
def test_module_inference(self):
infered = self.ast.infer()
obj = next(infered)