コード例 #1
0
ファイル: types_tests.py プロジェクト: mwilliamson/nope
 def common_super_type_of_types_is_passed_type_that_is_super_type_of_all_other_types(self):
     first_type = types.structural_type("first", [
         types.attr("a", types.int_type),
         types.attr("b", types.str_type),
     ])
     second_type = types.structural_type("second", [
         types.attr("a", types.int_type),
     ])
     assert_equal(second_type, types.common_super_type([first_type, second_type]))
コード例 #2
0
ファイル: call_tests.py プロジェクト: mwilliamson/nope
def generic_type_arguments_are_covariant():
    type_bindings = {"f": types.generic_func(["T"], lambda T:
        types.func([T, T], T),
    )}
    node = nodes.call(nodes.ref("f"), [nodes.str_literal(""), nodes.none()])
    assert_equal(
        types.common_super_type([types.str_type, types.none_type]),
        infer(node, type_bindings=type_bindings)
    )
コード例 #3
0
ファイル: call_tests.py プロジェクト: mwilliamson/nope
def return_type_is_common_super_type_of_possible_return_types_of_overloaded_function():
    type_bindings = {"f": types.overloaded_func(
        types.func([types.object_type], types.int_type),
        types.func([types.str_type], types.str_type),
    )}
    node = nodes.call(nodes.ref("f"), [nodes.str_literal("")])
    assert_equal(
        types.common_super_type([types.int_type, types.str_type]),
        infer(node, type_bindings=type_bindings)
    )
コード例 #4
0
ファイル: types_tests.py プロジェクト: mwilliamson/nope
 def common_super_type_of_unrelated_types_is_union_of_those_types(self):
     assert_equal(
         types.union(types.int_type, types.str_type),
         types.common_super_type([types.int_type, types.str_type]),
     )
コード例 #5
0
ファイル: types_tests.py プロジェクト: mwilliamson/nope
 def common_super_type_of_types_is_object_if_any_type_is_object(self):
     assert_equal(types.object_type, types.common_super_type([types.int_type, types.object_type]))
コード例 #6
0
ファイル: types_tests.py プロジェクト: mwilliamson/nope
 def common_super_type_of_zero_types_is_bottom_type(self):
     assert_equal(types.bottom_type, types.common_super_type([]))
コード例 #7
0
ファイル: types_tests.py プロジェクト: mwilliamson/nope
 def common_super_type_of_one_type_is_same_type(self):
     assert_equal(types.none_type, types.common_super_type([types.none_type]))