Decorators¶
The rite.functional.decorators submodule collects reusable decorators for common behaviors like debouncing, throttling, and deprecation warnings.
Decorators Module¶
Function decorators for control flow and behavior.
This submodule provides decorators for debouncing, throttling, one-time execution, and deprecation warnings.
Examples¶
from rite.functional.decorators import ( ... decorators_debounce, ... decorators_throttle, ... decorators_once ... ) @decorators_once() ... def initialize(): ... return "ready"
Modules¶
decorators_debounce
¶
Debounce Decorator¶
Delays function execution by specified wait time.
Examples¶
from rite.functional.decorators import decorators_debounce @decorators_debounce(0.5) ... def process(): ... return "done"
Functions¶
decorators_debounce(wait_time: float) -> Callable[[Callable[..., T]], Callable[..., T]]
¶
Decorator to debounce function call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait_time
|
float
|
Time to wait in seconds before execution. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
Decorated function that delays execution. |
Examples:
Notes
This implementation waits before each execution. For event-driven debouncing, use throttle pattern.
decorators_deprecated
¶
Deprecated Decorator¶
Mark functions as deprecated with warnings.
Examples¶
from rite.functional.decorators import decorators_deprecated @decorators_deprecated("Use new_function instead") ... def old_function(): ... pass
Functions¶
decorators_deprecated(message: str = 'This function is deprecated') -> Callable[[Callable[..., T]], Callable[..., T]]
¶
Decorator to mark function as deprecated.
Issues DeprecationWarning when function is called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Deprecation message to show. |
'This function is deprecated'
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
Decorated function that shows warning. |
Examples:
>>> @decorators_deprecated("Use process_v2() instead")
... def process_v1():
... return "old"
>>> process_v1()
'old'
Notes
Warnings can be controlled with warnings module.
decorators_once
¶
Once Decorator¶
Ensures function is called only once.
Examples¶
from rite.functional.decorators import decorators_once @decorators_once() ... def initialize(): ... return "initialized"
Functions¶
decorators_once() -> Callable[[Callable[..., T]], Callable[..., T]]
¶
Decorator to execute function only once.
Subsequent calls return cached result.
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T]]
|
Decorated function that runs once. |
Examples:
>>> @decorators_once()
... def setup():
... return "configured"
>>> setup()
'configured'
>>> setup() # Returns cached result
'configured'
Notes
Result is cached regardless of arguments. For argument-sensitive caching, use memoization.
decorators_throttle
¶
Throttle Decorator¶
Limits function execution frequency.
Examples¶
from rite.functional.decorators import decorators_throttle @decorators_throttle(1.0) ... def api_call(): ... return "response"
Functions¶
decorators_throttle(interval: float) -> Callable[[Callable[..., T]], Callable[..., T | None]]
¶
Decorator to throttle function calls.
Ensures function is not called more frequently than interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
float
|
Minimum time between calls in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., T]], Callable[..., T | None]]
|
Decorated function with throttling. |
Examples:
>>> @decorators_throttle(1.0)
... def process():
... return "done"
>>> process() # First call executes immediately
'done'
>>> process() # Subsequent calls within 1s are skipped
Notes
Returns None if called within throttle interval.
options: show_root_heading: true show_source: false heading_level: 2