summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-17 20:39:14 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-04-17 20:39:14 +0300
commitaa5d3cc86ee45d409d01e2dc4f575c0eeaad0788 (patch)
tree4d27ef7558f7daac7d0b447cd13d2481b7e40326
parent04444f62d6828db538cc1b4a127407ca2886c22d (diff)
downloadastroid-aa5d3cc86ee45d409d01e2dc4f575c0eeaad0788.tar.gz
UnboundMethod.getattr calls the getattr of its _proxied object.
It previously crashed, since it called super(...).getattr(..) and the first ancestor in its mro was bases.Proxy and bases.Proxy doesn't implement the .getattr method. Closes issue #91.
-rw-r--r--ChangeLog7
-rw-r--r--astroid/bases.py4
-rw-r--r--astroid/tests/unittest_nodes.py21
3 files changed, 30 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c7f633..ea3fd6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -43,6 +43,13 @@ Change log for the astroid package (used to be astng)
to the igetattr() method. It handled only the builtin property
but the new patch also handles abc.abstractproperty.
+ * UnboundMethod.getattr calls the getattr of its _proxied object
+ and doesn't call super(...) anymore.
+
+ It previously crashed, since the first ancestor in its mro was
+ bases.Proxy and bases.Proxy doesn't implement the .getattr method.
+ Closes issue #91.
+
2015-03-14 -- 1.3.6
diff --git a/astroid/bases.py b/astroid/bases.py
index 7de2c30..098a08a 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -262,12 +262,12 @@ class UnboundMethod(Proxy):
def getattr(self, name, context=None):
if name == 'im_func':
return [self._proxied]
- return super(UnboundMethod, self).getattr(name, context)
+ return self._proxied.getattr(name, context)
def igetattr(self, name, context=None):
if name == 'im_func':
return iter((self._proxied,))
- return super(UnboundMethod, self).igetattr(name, context)
+ return self._proxied.igetattr(name, context)
def infer_call_result(self, caller, context):
# If we're unbound method __new__ of builtin object, the result is an
diff --git a/astroid/tests/unittest_nodes.py b/astroid/tests/unittest_nodes.py
index 357e9aa..1d73362 100644
--- a/astroid/tests/unittest_nodes.py
+++ b/astroid/tests/unittest_nodes.py
@@ -455,5 +455,26 @@ class ArgumentsNodeTC(unittest.TestCase):
self.assertEqual(new.args.fromlineno, 0)
+class UnboundMethodNodeTest(unittest.TestCase):
+
+ def test_no_super_getattr(self):
+ # This is a test for issue
+ # https://bitbucket.org/logilab/astroid/issue/91, which tests
+ # that UnboundMethod doesn't call super when doing .getattr.
+
+ ast = test_utils.build_module('''
+ class A(object):
+ def test(self):
+ pass
+ meth = A.test
+ ''')
+ node = next(ast['meth'].infer())
+ with self.assertRaises(NotFoundError):
+ node.getattr('__missssing__')
+ name = node.getattr('__name__')[0]
+ self.assertIsInstance(name, nodes.Const)
+ self.assertEqual(name.value, 'test')
+
+
if __name__ == '__main__':
unittest.main()