diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-04-18 20:49:10 -0600 |
---|---|---|
committer | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-04-19 13:41:40 -0600 |
commit | 8575ac1c0bd247bc314f6752355d1ea647dec911 (patch) | |
tree | 7b55c83efcceed5d43e998fffdf8a84b1101cfe7 | |
parent | c56cb34d2b7782097d4e2ba2e2b08081ca7aad55 (diff) | |
download | astroid-git-8575ac1c0bd247bc314f6752355d1ea647dec911.tar.gz |
Add qname method to Super objects
Super objects in python have a __qualname__ attribute
so super nodes should have an equivalent qname method.
Prevents an error in upstream pylint
Close #533
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | astroid/objects.py | 3 | ||||
-rw-r--r-- | astroid/tests/unittest_objects.py | 13 |
3 files changed, 21 insertions, 0 deletions
@@ -75,6 +75,11 @@ Change log for the astroid package (used to be astng) Close #112 + * Add qname method to Super object preventing potential errors in upstream + pylint + + Close #533 + 2017-12-15 -- 1.6.0 diff --git a/astroid/objects.py b/astroid/objects.py index 7a873449..07ebbc8f 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -118,6 +118,9 @@ class Super(node_classes.NodeNG): """Get the name of the MRO pointer.""" return self.mro_pointer.name + def qname(self): + return "super" + def igetattr(self, name, context=None): """Retrieve the inferred values of the given attribute name.""" diff --git a/astroid/tests/unittest_objects.py b/astroid/tests/unittest_objects.py index 0dba8dea..dd317b61 100644 --- a/astroid/tests/unittest_objects.py +++ b/astroid/tests/unittest_objects.py @@ -502,6 +502,19 @@ class SuperTests(unittest.TestCase): self.assertIsInstance(inferred, nodes.Const) self.assertEqual(inferred.value, 42) + def test_super_qname(self): + """Make sure a Super object generates a qname + equivalent to super.__qname__ + """ + # See issue 533 + code = """ + class C: + def foo(self): return super() + C().foo() #@ + """ + super_obj = next(builder.extract_node(code).infer()) + self.assertEqual(super_obj.qname(), "super") + if __name__ == '__main__': unittest.main() |