Beispiel #1
0
def test_optimization_multiple_list_comprehensions():
    from typing import List
    from tmppy import Type
    def f(l0: List[Type]):
        l1 = [Type.pointer(x) for x in l0]
        l2 = [Type.const(x) for x in l1]
        return l2
    assert f([Type('int'), Type('float')]) == [Type.const(Type.pointer(Type('int'))),
                                               Type.const(Type.pointer(Type('float')))]
Beispiel #2
0
 def f(t: Type):
     return match(t)(lambda T: {
         Type.const(T):
             T,
         T:
             Type('double'),
     })
Beispiel #3
0
def test_const_type_expr_as_match_expr_matched_success():
    from tmppy import Type, match

    def f(t: Type):
        return match(t)(lambda T: {
            Type.const(T): T,
            T: Type('double'),
        })

    assert f(Type.const(Type('int'))) == Type('int')
Beispiel #4
0
 def f(l0: List[Type]):
     l1 = [Type.pointer(x) for x in l0]
     l2 = [Type.const(x) for x in l1]
     return l2
Beispiel #5
0
def test_const_type_literal_success():
    from tmppy import Type
    assert Type.const(Type('int')) == Type.const(Type('int'))
Beispiel #6
0
 def f(x: bool):
     return Type.const(
         5
     )  # error: The argument passed to Type.const\(\) should have type Type, but was: int
Beispiel #7
0
 def f(x: bool):
     return Type.const(
         'x', 'y')  # error: Type.const\(\) takes 1 argument. Got: 2
Beispiel #8
0
 def f(x: bool):
     return Type.const(
         x=1
     )  # error: Keyword arguments are not supported in Type.const\(\)