with_default_return#
- with_default_return(default_return: Dict[str, Any]) Callable[[F], F] [source]#
Decorator to add a default_return attribute to a function.
This decorator adds a
default_return
attribute to the decorated function, which can be used for error handling to provide properly structured returns when the function cannot execute normally.- Parameters:
- default_returndict
Dictionary containing the default structure to be returned in error cases. Keys should match the expected return structure of the decorated function.
- Returns:
- callable
Decorator function that attaches the default_return attribute to the target function.
Note
This decorator preserves the original function’s signature, docstring, and other attributes.
Examples
>>> @with_default_return( ... {"tagged_items": [], "non_tagged_items": []} ... ) ... def extract_items(content): ... # Function implementation ... return { ... "tagged_items": ["item1"], ... "non_tagged_items": ["item2"], ... } >>> extract_items.default_return {'tagged_items': [], 'non_tagged_items': []}