summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--astroid/inference.py2
-rw-r--r--astroid/tests/unittest_inference.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 0a55b6e8..a0a933eb 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -520,6 +520,8 @@ def _is_not_implemented(const):
def _invoke_binop_inference(instance, opnode, op, other, context, method_name):
"""Invoke binary operation inference on the given instance."""
methods = dunder_lookup.lookup(instance, method_name)
+ if context is not None:
+ context.boundnode = instance
method = methods[0]
inferred = next(method.infer(context=context))
return instance.infer_binary_op(opnode, op, other, context, inferred)
diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py
index b4e97923..29748507 100644
--- a/astroid/tests/unittest_inference.py
+++ b/astroid/tests/unittest_inference.py
@@ -895,6 +895,15 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
self.assertEqual('module.C', should_be_C[0].qname())
self.assertEqual('module.D', should_be_D[0].qname())
+ def test_factory_methods_inside_binary_operation(self):
+ node = extract_node("""
+ from pathlib import Path
+ h = Path("/home")
+ u = h / "user"
+ u #@
+ """)
+ assert next(node.infer()).qname() == 'pathlib.Path'
+
def test_import_as(self):
code = '''
import os.path as osp