summaryrefslogtreecommitdiff
path: root/astroid/node_classes.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-03-10 10:33:35 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2020-03-10 10:33:35 +0100
commit77e205dc64ead82e38bb901e08117ef6f6162c5c (patch)
tree8fbd409badeee2ed517ba368ee521a790c0f28fd /astroid/node_classes.py
parent00bcf7b817ed459ee617b8af8843aca18d72fe04 (diff)
downloadastroid-git-77e205dc64ead82e38bb901e08117ef6f6162c5c.tar.gz
Add a new EvaluatedObject container
This container is used to store values that have already been evaluated. For instance, 79d5a3a783cf0b5a729e4e467508e955a0cca55f added support for inferring `tuple()` call arguments, but as a result, the `elts` of a `Tuple` can be objects not *references*. As a result, `Tuple.elts` can contain class objects rather than references (names) to class object. The `EvaluatedObject` helps with that, as we still have to call `.infer()` (albeit a no-op) to grab the inferred value of an element.
Diffstat (limited to 'astroid/node_classes.py')
-rw-r--r--astroid/node_classes.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 2e03f4ea..f16b61bd 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -4726,6 +4726,40 @@ class Unknown(mixins.AssignTypeMixin, NodeNG):
yield util.Uninferable
+class EvaluatedObject(NodeNG):
+ """Contains an object that has already been inferred
+
+ This class is useful to pre-evaluate a particular node,
+ with the resulting class acting as the non-evaluated node.
+ """
+
+ name = "EvaluatedObject"
+ _astroid_fields = ("original",)
+ _other_fields = ("value",)
+
+ original = None
+ """The original node that has already been evaluated
+
+ :type: NodeNG
+ """
+
+ value = None
+ """The inferred value
+
+ :type: Union[Uninferable, NodeNG]
+ """
+
+ def __init__(self, original, value):
+ self.original = original
+ self.value = value
+ self.lineno = self.original.lineno
+ self.parent = self.original.parent
+ self.col_offset = self.original.col_offset
+
+ def infer(self, context=None, **kwargs):
+ yield self.value
+
+
# constants ##############################################################
CONST_CLS = {