Ejemplo n.º 1
0
def dict_literal_uses_type_hint_when_valid():
    assert_equal(
        types.dict_type(types.object_type, types.int_type),
        infer(nodes.dict_literal([
            (nodes.str_literal("Hello"), nodes.int_literal(42)),
        ]), hint=types.dict_type(types.object_type, types.int_type))
    )
    assert_equal(
        types.dict_type(types.str_type, types.object_type),
        infer(nodes.dict_literal([
            (nodes.str_literal("Hello"), nodes.int_literal(42)),
        ]), hint=types.dict_type(types.str_type, types.object_type))
    )
Ejemplo n.º 2
0
def dict_literal_type_hint_is_ignored_if_hint_item_type_is_not_super_type_of_actual_item_types():
    assert_equal(
        types.dict_type(types.str_type, types.int_type),
        infer(nodes.dict_literal([
            (nodes.str_literal("Hello"), nodes.int_literal(42)),
        ]), hint=types.dict_type(types.bottom_type, types.int_type))
    )
    assert_equal(
        types.dict_type(types.str_type, types.int_type),
        infer(nodes.dict_literal([
            (nodes.str_literal("Hello"), nodes.int_literal(42)),
        ]), hint=types.dict_type(types.str_type, types.bottom_type))
    )
Ejemplo n.º 3
0
def type_of_dict_is_determined_by_unifying_types_of_keys_and_values():
    assert_equal(
        types.dict_type(types.str_type, types.int_type),
        infer(nodes.dict_literal([
            (nodes.str_literal("Hello"), nodes.int_literal(42)),
            (nodes.str_literal("Blah"), nodes.int_literal(16)),
        ]))
    )
Ejemplo n.º 4
0
def empty_dict_has_key_and_value_type_of_bottom():
    assert_equal(
        types.dict_type(types.bottom_type, types.bottom_type),
        infer(nodes.dict_literal([]))
    )
Ejemplo n.º 5
0
def dict_literal_type_hint_is_ignored_if_hint_type_is_not_dict():
    assert_equal(
        types.dict_type(types.bottom_type, types.bottom_type),
        infer(nodes.dict_literal([]), hint=types.int_type)
    )