Exemplo n.º 1
0
 def visit_subscript(self, node, parent, assign_ctx=None):
     """visit a Subscript node by returning a fresh instance of it"""
     newnode = new.Subscript()
     _lineno_parent(node, newnode, parent)
     newnode.value = self.visit(node.value, newnode, None)
     newnode.slice = self.visit(node.slice, newnode, None)
     return newnode
Exemplo n.º 2
0
def test_inference_invalid_slice(node):
    sub_node = nodes.Subscript()
    slice = nodes.Slice()
    slice.postinit(nodes.Const(0), nodes.Const("a"))
    sub_node.postinit(node, slice)
    module, _ = cs._parse_text(sub_node)
    for subscript_node in module.nodes_of_class(nodes.Subscript):
        assert isinstance(subscript_node.inf_type, TypeFail)
Exemplo n.º 3
0
 def visit_subscript(self, node, parent):
     """visit a Subscript node by returning a fresh instance of it"""
     newnode = new.Subscript()
     _lineno_parent(node, newnode, parent)
     subcontext, self.asscontext = self.asscontext, None
     newnode.value = self.visit(node.value, newnode)
     newnode.slice = self.visit(node.slice, newnode)
     self.asscontext = subcontext
     return newnode
Exemplo n.º 4
0
 def visit_subscript(self, node, parent):
     """visit a Subscript node by returning a fresh instance of it"""
     context = self._get_context(node)
     newnode = nodes.Subscript(ctx=context,
                               lineno=node.lineno,
                               col_offset=node.col_offset,
                               parent=parent)
     newnode.postinit(self.visit(node.value, newnode),
                      self.visit(node.slice, newnode))
     return newnode
Exemplo n.º 5
0
def test_inference_dict_subscript(node):
    """Note that this test only takes in a dictionary because the subscript index
    must be the same type as the dictionary's keys in order to type check.
    """
    for key, _ in node.items:
        new_node = nodes.Subscript()
        new_node.postinit(node, key)
        module, _ = cs._parse_text(new_node)
        for subscript_node in module.nodes_of_class(nodes.Subscript):
            dict_node = subscript_node.value
            assert (subscript_node.inf_type.getValue() == list(
                dict_node.items)[0][1].inf_type.getValue())
Exemplo n.º 6
0
def subscript_node(draw, value=None, slice=const_node(hs.integers())):
    value = value or subscriptable_expr
    node = nodes.Subscript()
    node.postinit(draw(value), draw(slice))
    return node