Beispiel #1
0
def assignment_to_tuple_unpacks_tuple_type():
    node = nodes.assign(
        [nodes.tuple_literal([nodes.ref("x"), nodes.ref("y")])],
        nodes.ref("value")
    )
    context = update_context(node, type_bindings={
        "value": types.tuple_type(types.int_type, types.str_type),
    })
    assert_equal(types.int_type, context.lookup_name("x"))
    assert_equal(types.str_type, context.lookup_name("y"))
Beispiel #2
0
def assignment_to_tuple_must_have_correct_length_tuple():
    tuple_node = nodes.tuple_literal([nodes.ref("x"), nodes.ref("y")])
    node = nodes.assign(
        [tuple_node],
        nodes.ref("value")
    )
    try:
        update_context(node, type_bindings={
            "value": types.tuple_type(types.int_type),
        })
        assert False, "Expected error"
    except errors.UnpackError as error:
        assert_equal(tuple_node, error.node)
        assert_equal("need 2 values to unpack, but only have 1" , str(error))
Beispiel #3
0
def can_infer_type_of_list_of_two_tuple():
    assert_equal(
        types.tuple_type(types.int_type, types.str_type),
        infer(nodes.tuple_literal([nodes.int_literal(1), nodes.str_literal("42")]))
    )