コード例 #1
0
ファイル: literals_tests.py プロジェクト: mwilliamson/nope
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))
    )
コード例 #2
0
ファイル: literals_tests.py プロジェクト: mwilliamson/nope
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))
    )
コード例 #3
0
ファイル: literals_tests.py プロジェクト: mwilliamson/nope
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)),
        ]))
    )
コード例 #4
0
ファイル: literals_tests.py プロジェクト: mwilliamson/nope
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([]))
    )
コード例 #5
0
ファイル: literals_tests.py プロジェクト: mwilliamson/nope
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)
    )