summaryrefslogtreecommitdiff
path: root/astroid/context.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/context.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/context.py')
-rw-r--r--astroid/context.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/astroid/context.py b/astroid/context.py
index 3461fb2b..75cab636 100644
--- a/astroid/context.py
+++ b/astroid/context.py
@@ -136,3 +136,28 @@ def copy_context(context):
return context.clone()
return InferenceContext()
+
+
+def bind_context_to_node(context, node):
+ """Give a context a boundnode
+ to retrieve the correct function name or attribute value
+ with from further inference.
+
+ Do not use an existing context since the boundnode could then
+ be incorrectly propagated higher up in the call stack.
+
+ :param context: Context to use
+ :type context: Optional(context)
+
+ :param node: Node to do name lookups from
+ :type node NodeNG:
+
+ :returns: A new context
+ :rtype: InferenceContext
+ """
+ if context is not None:
+ context = context.clone()
+ else:
+ context = InferenceContext()
+ context.boundnode = node
+ return context