Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeertmans/strong
Simple dynamic Python type checker
https://github.com/jeertmans/strong
dynamic function-signatures python type-checker
Last synced: 12 days ago
JSON representation
Simple dynamic Python type checker
- Host: GitHub
- URL: https://github.com/jeertmans/strong
- Owner: jeertmans
- License: mit
- Created: 2020-10-06T15:24:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-17T17:44:43.000Z (almost 4 years ago)
- Last Synced: 2024-11-22T23:36:44.933Z (29 days ago)
- Topics: dynamic, function-signatures, python, type-checker
- Language: Python
- Homepage:
- Size: 842 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
![](https://img.shields.io/readthedocs/strong) ![](https://img.shields.io/pypi/v/strong) ![](https://img.shields.io/pypi/pyversions/strong)
# 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](https://strong.readthedocs.io/en/latest/).
## 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.
```python
>>> 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 "", line 3
Argument `b` does not match typing: '2' is not an instance of
>>> 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
```