Decorator Style Integration#
Use this pattern when digestion logic should stay next to API code.
Structure#
mylib/
api.py
Co-located digesters#
from argdigest import arg_digest, argument_digest
@argument_digest("selection")
def digest_selection(selection, syntax="MolSysMT", caller=None):
if selection is None:
return "all"
return str(selection)
@argument_digest("syntax")
def digest_syntax(syntax, caller=None):
if syntax is None:
return "MolSysMT"
return str(syntax)
Decorated function#
@arg_digest(digestion_style="decorator", strictness="error",
unknown_argument="error")
def get(molecular_system, selection=None, syntax="MolSysMT"):
return molecular_system, selection, syntax
Why this style works#
Digesters are versioned with the same module as the API function.
Refactors are simple because digesters move with the function.
Plugin modules can register additional digesters without touching package registries.
The function contract is style-independent#
Digestion style decides how per-argument digesters are found. It says nothing about which
arguments a function may receive, which is declared through FUNCTION_SOURCE whichever
style you pick — and a closed signature needs no declaration at all.
Smoke check#
call with
selection=Noneand verify default normalization.call with explicit
syntaxand verify no warning/error noise.call with malformed values and verify catalog-backed digest errors.
Call with a mistyped keyword and confirm it is refused, not ignored. A closed signature gives you this with nothing declared.