Home

Awesome

Typity

Typing Tools

Example

Annotate

asciicast

from typity.annotate import annotate

assert (
    annotate({"a": [1, 2, "abc"], "c": b"ddd"})
    is typing.Dict[str, typing.Union[bytes, typing.List[typing.Union[str, int]]]]
)

Basic Resolving

asciicast

from typity.resolver import Resolver
r = Resolver()
assert r.dispatch(typing.Union[typing.List[int], typing.Tuple[str]], [15, 30])

Verifiying Types at Runtime

from typity.verify import verify
@verify
def add(x: typing.List[int], y: int) -> int:
    pass

add([3], 2)
with pytest.raises(TypeError):
    add(1, 2)

Transforming Return Type

from typity.transform import transform
@transform
def add(x, y) -> str:
    return x + y

assert type(add(3, 2)) is str