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
Built Distribution
File details
Details for the file strong-0.2.2.tar.gz
.
File metadata
- Download URL: strong-0.2.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c73f513ec8b901b7389a7b040cc5ae7aadb45691a5260babfae48d3374fded50 |
|
MD5 | 7c884808cd10e8404192f6f5e76f4c5c |
|
BLAKE2b-256 | fc2d6baef7a8d7df2fc40fe0a7454855d95b3e08e17ebab285c05434d9fd1257 |
File details
Details for the file strong-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: strong-0.2.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7391cba7a66daf6387984444a6a108580237a0bcd2f1327db0d781f456cfd0cc |
|
MD5 | 833b8ad909b39acc14ba937fac5e286e |
|
BLAKE2b-256 | 04c9675133ee290ad820c17c9ca0d41f3cce480bce9c57a95aefd742cea67905 |