Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 2.13 KB

README.md

File metadata and controls

62 lines (46 loc) · 2.13 KB

Release status PyPI package Supported Python versions Build Status Coverage Status Documentation Status Pypi downloads Pypi downloads

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.
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.

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