diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-28 20:51:03 -0600 |
---|---|---|
committer | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-03-30 21:45:07 -0700 |
commit | 6a3b33afb1be93e4d1a2b989ce31af24ece1137f (patch) | |
tree | 4e4f7a4ff421e3d778307f48fb94fdd033ed7be9 | |
parent | fda4d06680e67284c89fea56b3b22dee0980d992 (diff) | |
download | astroid-git-6a3b33afb1be93e4d1a2b989ce31af24ece1137f.tar.gz |
Set context boundnode for binary operation to correct inference
-rw-r--r-- | astroid/inference.py | 2 | ||||
-rw-r--r-- | astroid/tests/unittest_inference.py | 9 |
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 |