`ornaments` helps to *future-proofly* document the intent of one's `python` code.
It aims to do so through meaningful @decorator functions that help other developers understand, (re-)use, and debug your code.
A @decorator 'talks about' other code in a way that is understandable for both the human reader as well as the interpreter. By being meaningful to both, @decorator based documentation can bypass the (all to common) disconnect between documentation and code.
ornaments provides functionality for adding various
- value/type checks (as well limiters for input/execution duration) during runtime
- context-dependend logging functionalities (i.e. execution time)
- testable meta information (i.e. deprecation warnings)
from ornaments.invariants import only_called_once
@only_called_once(scope="session", enforce=True)
def only_once_callable_function() -> None:
return None
# -----
only_once_callable_function()
>>> None
# This should raise an error
only_once_callable_function()
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
only_once_callable_function()
File "./ornaments/src/ornaments/invariants/only_called_once.py", line 45, in wrapper
raise CalledTooOftenError(msg)
ornaments._exceptions.CalledTooOftenError: Function only_once_callable_function has already been called in session. call_scope=(4522676512, <function only_once_callable_function at 0x10d929120>)from ornaments.invariants import only_called_once
def my_reusable_function() -> None:
return None
@only_called_once(scope="session", enforce=True)
def only_once_callable_function() -> None:
return my_reusable_function()
# -----
my_reusable_function()
>>> None
my_reusable_function()
>>> None
only_once_callable_function()
>>> None
# This should raise an error
only_once_callable_function()
>>> Traceback (most recent call last):
File "<input>", line 1, in <module>
only_once_callable_function()
File "./ornaments/src/ornaments/invariants/only_called_once.py", line 45, in wrapper
raise CalledTooOftenError(msg)
...π
ornaments
βββ helpers
βΒ Β βββ catch_all_exceptions.py
βΒ Β βββ normalized_exceptions.py
βΒ Β βββ retry.py
βββ invariants
βΒ Β βββ conditional_execution.py
βΒ Β βββ only_called_once.py
βββ limits
βΒ Β βββ call_limit.py
βΒ Β βββ execution_time_limit.py
βββ logging
βΒ Β βββ log_calls.py
βΒ Β βββ log_execution_time.py
βΒ Β βββ log_parameters.py
βΒ Β βββ log_return.py
βΒ Β βββ log_value.py
βββ markers
βΒ Β βββ stable.py
βΒ Β βββ wobbly.py
βΒ Β βββ deprecated.py
βββ monitoring
βΒ Β βββ monitored_attribute.py
βΒ Β βββ monitored_calls.py
βββ runtime_checks
βΒ Β βββ checked_return_type.py
βΒ Β βββ parameter_validation.py
βββ safety
Β Β βββ fallback_function.pySee
CONTRIBUTING.mdfor information on how to setup and contribute to this project.
.::=+=--++=::.
.-+++*-+++ =*+*=++=-:
:+#+-=:-.:+--+++=.=+:=**=.
.+#==::--+#*-...:=%%+-:**==*=
.@%=*=+:*#*. .#@#-==-==-*.
#@--+=-##:: %@#=:=:+::=
-@@:==+:%+-. =@=:++=:: -.
*@@:-==:%*-. =@*+=+-+-.-.
:@@:.-==+@%- %@===+==: =.
#@-++-=--#%= :%%----=:. :=
#@=.:-:+++++==:--++=.::=++..:+
:*%#*=:*+: -==:#%#*.==+::..--
::-+**=++-:=--.*%%%==--.:::.
:--:==-:--:--:-:::::
. . : : ...Author - MultifokalHirn



