summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-07-02 09:57:36 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-07-02 09:57:36 +0300
commit637aeb8ec8a1442d9035d259852c87ab5d84c9f9 (patch)
tree5312a00691fb9cadc5758e4f4bb8cdd3cd9fdf6e
parentcbb692733106c608a6f9b89e08638d1866704b48 (diff)
downloadastroid-637aeb8ec8a1442d9035d259852c87ab5d84c9f9.tar.gz
Add support for inferring methods masquerading as others for the binop protocols.
-rw-r--r--astroid/inference.py3
-rw-r--r--astroid/tests/unittest_inference.py14
2 files changed, 16 insertions, 1 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 3864f43..fda5f2e 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -429,7 +429,8 @@ def _is_not_implemented(const):
def _invoke_binop_inference(instance, op, other, context, method_name):
"""Invoke binary operation inference on the given instance."""
method = instance.getattr(method_name)[0]
- return instance.infer_binary_op(op, other, context, method)
+ inferred = next(method.infer(context=context))
+ return instance.infer_binary_op(op, other, context, inferred)
def _aug_op(instance, op, other, context, reverse=False):
"""Get an inference callable for an augmented binary operation."""
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index f8fa0dd..87e6993 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -2644,6 +2644,20 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
inferred = next(rest.infer())
self.assertEqual(inferred, YES)
+ def test_special_method_masquerading_as_another(self):
+ ast_node = test_utils.extract_node('''
+ class Info(object):
+ def __add__(self, other):
+ return "lala"
+ __or__ = __add__
+
+ f = Info()
+ f | Info() #@
+ ''')
+ inferred = next(ast_node.infer())
+ self.assertIsInstance(inferred, nodes.Const)
+ self.assertEqual(inferred.value, "lala")
+
class GetattrTest(unittest.TestCase):