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.
pyoload provides two basic methods:
pyoload.annotate
: decorator over functions or methods.pyoload.annotate_class
: decorator over classes. All wrapped bypyoload()
which checks what to be called.
import pyoload
pyoload.debug()
@pyoload
def foo(a: int, b, c: str) -> tuple[str, int]:
return ("ab", 23)
@pyoload
class myclass:
pass
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.
You may add validators to check values furthermore.
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