summaryrefslogtreecommitdiff
path: root/astroid/protocols.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-02-16 18:44:53 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-02-16 19:04:04 +0000
commitfd1f8c78be2b295405111f5db05e47457ee618a5 (patch)
tree5420d4f90c709e4624f281171c133653843c52b3 /astroid/protocols.py
parent7a206c6851cd63a4028d6ce384f281f1ee460181 (diff)
downloadastroid-git-fd1f8c78be2b295405111f5db05e47457ee618a5.tar.gz
Set the parent to the BinOp node when inferring nodes created during binary operations
In order to do so, we had to change the signature of infer_binary_operation to receive the binary operation instead of the operator itself.
Diffstat (limited to 'astroid/protocols.py')
-rw-r--r--astroid/protocols.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 7fdc6e29..8ca9ee1c 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -148,7 +148,7 @@ def infer_binary_op(self, operator, other, context, method, nodes):
@infer_binary_op.register(treeabc.Const)
@decorators.yes_if_nothing_inferred
-def const_infer_binary_op(self, operator, other, context, _, nodes):
+def const_infer_binary_op(self, opnode, operator, other, context, _, nodes):
not_implemented = nodes.NameConstant(NotImplemented)
if isinstance(other, treeabc.Const):
try:
@@ -169,8 +169,8 @@ def const_infer_binary_op(self, operator, other, context, _, nodes):
yield not_implemented
-def _multiply_seq_by_int(self, other, context):
- node = self.__class__()
+def _multiply_seq_by_int(self, opnode, other, context):
+ node = self.__class__(parent=opnode)
elts = []
for elt in self.elts:
infered = inferenceutil.safe_infer(elt, context)
@@ -193,10 +193,10 @@ def _filter_uninferable_nodes(elts, context):
@infer_binary_op.register(treeabc.Tuple)
@infer_binary_op.register(treeabc.List)
@decorators.yes_if_nothing_inferred
-def tl_infer_binary_op(self, operator, other, context, method, nodes):
+def tl_infer_binary_op(self, opnode, operator, other, context, method, nodes):
not_implemented = nodes.NameConstant(NotImplemented)
if isinstance(other, self.__class__) and operator == '+':
- node = self.__class__()
+ node = self.__class__(parent=opnode)
elts = list(_filter_uninferable_nodes(self.elts, context))
elts += list(_filter_uninferable_nodes(other.elts, context))
node.elts = elts
@@ -205,21 +205,21 @@ def tl_infer_binary_op(self, operator, other, context, method, nodes):
if not isinstance(other.value, int):
yield not_implemented
return
- yield _multiply_seq_by_int(self, other, context)
+ yield _multiply_seq_by_int(self, opnode, other, context)
elif isinstance(other, runtimeabc.Instance) and operator == '*':
# Verify if the instance supports __index__.
as_index = inferenceutil.class_instance_as_index(other)
if not as_index:
yield util.Uninferable
else:
- yield _multiply_seq_by_int(self, as_index, context)
+ yield _multiply_seq_by_int(self, opnode, as_index, context)
else:
yield not_implemented
@infer_binary_op.register(runtimeabc.Instance)
@decorators.yes_if_nothing_inferred
-def instance_infer_binary_op(self, operator, other, context, method, nodes):
+def instance_infer_binary_op(self, opnode, operator, other, context, method, nodes):
return method.infer_call_result(self, context)