https://github.com/ken-morel/pyoload
Add some runtime typchecking to your functions and classes.
https://github.com/ken-morel/pyoload
annotations function-arguments multiple-dispatch overloading pymodule pypi-package python typechecker
Last synced: 13 days ago
JSON representation
Add some runtime typchecking to your functions and classes.
- Host: GitHub
- URL: https://github.com/ken-morel/pyoload
- Owner: ken-morel
- License: mit
- Created: 2024-05-01T22:56:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-18T23:59:52.000Z (4 months ago)
- Last Synced: 2025-08-19T01:23:10.102Z (4 months ago)
- Topics: annotations, function-arguments, multiple-dispatch, overloading, pymodule, pypi-package, python, typechecker
- Language: Python
- Homepage: https://github.com/ken-morel/pyoload
- Size: 14.8 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/ken-morel/pyoload/releases)
[](https://pypi.org/project/pyoload)
[](https://pypi.org/project/pyoload)
[](https://github.com/ken-morel/pyoload/tree/mai)
[](https://coveralls.io/github/ken-morel/pyoload?branch=main)
[](https://pyoload.readthedocs.io)
[](https://pypi.org/project/pyoload)
[](https://pypi.org/project/pyoload)
[](https://wakatime.com/badge/github/ken-morel/pyoload)
# pyoload
This adds some runtime type checking and warnings when enabled. It is disabled
by default.
Pyoload permits you to add runtime checking to classes on instance attribute
assignment and functions.
## usage
pyoload provides two basic methods:
- `pyoload.annotate`: decorator over functions or methods.
- `pyoload.annotate_class`: decorator over classes.
All wrapped by `pyoload()` which checks what to be called.
```py
import pyoload
pyoload.debug()
@pyoload
def foo(a: int, b, c: str) -> tuple[str, int]:
return ("ab", 23)
@pyoload
class myclass:
pass
```
## pyolaod modes
Pyoload includes three modes of enum type `pyoload.Mode` and where the current
mode is in `pyoload.MODE`.
* **DEBUG**: Shows warnings, comments, exceptions activate via `pyoload.debug()`
* **DEV** : Does not call upon validatore
* **PROD**(*DEFAULT*): `@pyoload` simply does nothing.
## Adding validators
You may add validators to check values furthermore.
```py
def validator(value) -> Optional[str]:
if value.is_ok():
return None
else:
return "Value is not Ok! pass a value which is Ok please."
@pyoload(comments=dict(val=validator))
def func(val):
pass
```