diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-01-14 23:11:24 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-01-14 23:11:24 +0200 |
commit | b660d0c88a7e72049ee1299b0bcef84345626d0d (patch) | |
tree | 75e0e20830aa886f42d14ba4a7010987436f3178 | |
parent | d3b35124ecccac0a2daed6c92f9d7a8e719d8a5d (diff) | |
download | astroid-git-b660d0c88a7e72049ee1299b0bcef84345626d0d.tar.gz |
Support accessing properties using super().
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | astroid/objects.py | 4 | ||||
-rw-r--r-- | astroid/tests/unittest_objects.py | 18 |
3 files changed, 24 insertions, 0 deletions
@@ -2,6 +2,8 @@ Change log for the astroid package (used to be astng) ===================================================== -- + * Support accessing properties with super(). + * Enforce strong updates per frames. When looking up a name in a scope, Scope.lookup will return diff --git a/astroid/objects.py b/astroid/objects.py index e948396f..35c9b1a9 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -173,6 +173,10 @@ class Super(node_classes.NodeNG): yield inferred elif self._class_based or inferred.type == 'staticmethod': yield inferred + elif bases._is_property(inferred): + # TODO: support other descriptors as well. + for value in inferred.infer_call_result(self, context): + yield value else: yield bases.BoundMethod(inferred, cls) diff --git a/astroid/tests/unittest_objects.py b/astroid/tests/unittest_objects.py index dc91d94e..db30771f 100644 --- a/astroid/tests/unittest_objects.py +++ b/astroid/tests/unittest_objects.py @@ -494,6 +494,24 @@ class SuperTests(unittest.TestCase): with self.assertRaises(exceptions.SuperError):
inferred.super_mro()
+ def test_super_properties(self):
+ node = test_utils.extract_node('''
+ class Foo(object):
+ @property
+ def dict(self):
+ return 42
+
+ class Bar(Foo):
+ @property
+ def dict(self):
+ return super(Bar, self).dict
+
+ Bar().dict
+ ''')
+ inferred = next(node.infer())
+ self.assertIsInstance(inferred, nodes.Const)
+ self.assertEqual(inferred.value, 42)
+
if __name__ == '__main__':
unittest.main()
|