Skip to main content

Dynamic type checker for function signatures

Project description

Strong - Dynamic type checker for function signatures

Strong embraces the builtin typing package by providing dynamic type checking for function signatures.

Install:

Simply use:

pip install strong

Documentation:

The documentation is hosted here.

Example:

Let's say you have a function taking two inputs, a and b, and returning one output. In Python, you can use type-hint in order to give clue about the type the parameters should have. Nonetheless, Python will not block inputs with the wrong type.

This package is here to provide tools to make the task of checking input parameters type easy.

>>> from strong.core.decorators import assert_correct_typing

>>> @assert_correct_typing
>>> def f(a: int, b: int) -> int:
>>>     return a + b

>>> x = f(1, 2)  # O.K.

>>> y = f(1, '2')  # K.O.
AssertionError: Function f defined in "<function_file>", line 3
    Argument `b` does not match typing: '2' is not an instance of <class 'int'>
>>> from strong.core.decorators import measure_overhead
>>> import numpy as np

>>> @measure_overhead(assert_correct_typing)
>>> def g(a: int, b: int) -> np.ndarray:
        return np.random.rand(a, b)

>>> g(100, 100)
1.0687804670719938  # Ratio between time taken with @assert_correct_typing and without

Project details


Download files

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

Source Distribution

strong-0.2.2.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

strong-0.2.2-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page