Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Typing Tools

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for typity, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size typity-0.4.1.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page