def test_fromcallable(target_info): def foo(a: int, b: float) -> int: pass assert Type.fromcallable(foo) == Type.fromstring('i64(i64,d)') def foo(a: 'int32', b): # noqa: F821 pass assert Type.fromcallable(foo) == Type.fromstring('void(i32,<type of b>)') with pytest.raises( ValueError, match=(r'constructing Type instance from' r' a lambda function is not supported')): Type.fromcallable(lambda a: a) with pytest.raises( ValueError, match=r'callable argument kind must be positional'): def foo(*args): pass Type.fromcallable(foo)
def Type_fromcallable(s): return Type.fromcallable(s, target_info)