示例#1
0
def test_unify_record():
    rec_type = Record[{'a': TypeVar[None]}]
    unify(rec_type, Record[{'a': IntType}])
    check_eq(rec_type, Record[{'a': IntType}])

    with py.test.raises(TypeCheckError):
        unify(Record[{'a': IntType}], Record[{'a': StringType}])
示例#2
0
def test_unify_union():
    a = Union[StringType, IntType]
    unify(a, a)
    with py.test.raises(TypeCheckError):
        unify(a, StringType)
    unify(IntType, a)
    unify(StringType, a)
示例#3
0
def test_unify_type_var():
    a = TypeVar[None]
    unify(a, IntType)
    check_eq(a.__instance__, IntType)

    b = TypeVar[None]
    unify(IntType, b)
    check_eq(b.__instance__, IntType)

    with py.test.raises(TypeCheckError):
        unify(TypeVar[IntType], StringType)
示例#4
0
def test_unify_subtype():
    a = TypeVar[BoolType]
    a.__backref__ = ArgRef('arg')
    unify(a, IntType)
    assert isinstance(IntType, type(a.__instance__))
    check_eq(a.__instance__, IntType)

    b = TypeVar[None]
    b.__backref__ = ArgRef('arg')
    unify(b, Record[{'a': BoolType, 'b': BoolType}])
    unify(b, Record[{'b': IntType, 'c': IntType}])
    check_eq(b, Record[{
        'a': BoolType, 'b': IntType, 'c': IntType,
    }])
示例#5
0
def test_unify_dict():
    dict_type = DictType[TypeVar[None], TypeVar[None]]
    unify(dict_type, DictType[StringType, IntType])
    check_eq(dict_type.__key_type__.__instance__, StringType)
    check_eq(dict_type.__value_type__.__instance__, IntType)
示例#6
0
def test_unify_list():
    list_type = ListType[TypeVar[None]]
    unify(list_type, ListType[IntType])
    check_eq(list_type.__item_type__.__instance__, IntType)
示例#7
0
def test_unify_type():
    unify(IntType, IntType)

    with py.test.raises(TypeCheckError):
        unify(IntType, StringType)