summaryrefslogtreecommitdiff
path: root/astroid/inference.py
diff options
context:
space:
mode:
authorBryce Guinta <bryce.paul.guinta@gmail.com>2018-07-03 17:50:43 -0600
committerClaudiu Popa <pcmanticore@gmail.com>2018-07-04 08:27:21 +0200
commit045787fd104032780dcb47445d79035c1f45f08a (patch)
tree402d047d6aa2f98351d6bd596f506b1dab97676e /astroid/inference.py
parent7f13c2cd2f02b202a6793c059d98437e02d383cc (diff)
downloadastroid-git-045787fd104032780dcb47445d79035c1f45f08a.tar.gz
Refactor assinging boundnode to context
Code in multiple places had the same pattern for infering call results.
Diffstat (limited to 'astroid/inference.py')
-rw-r--r--astroid/inference.py11
1 files changed, 4 insertions, 7 deletions
diff --git a/astroid/inference.py b/astroid/inference.py
index 33730a39..b9e098b4 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -537,8 +537,7 @@ 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
+ context = contextmod.bind_context_to_node(context, instance)
method = methods[0]
inferred = next(method.infer(context=context))
if inferred is util.Uninferable:
@@ -824,14 +823,12 @@ nodes.Index._infer = infer_index
# will be solved.
def instance_getitem(self, index, context=None):
# Rewrap index to Const for this case
- if context:
- new_context = context.clone()
- else:
- context = new_context = contextmod.InferenceContext()
+ new_context = contextmod.bind_context_to_node(context, self)
+ if not context:
+ context = new_context
# Create a new callcontext for providing index as an argument.
new_context.callcontext = contextmod.CallContext(args=[index])
- new_context.boundnode = self
method = next(self.igetattr('__getitem__', context=context), None)
if not isinstance(method, bases.BoundMethod):