Context Module
Context management for PepperPy.
This module provides a robust context management system that supports:
- Context chaining
- Resource scoping
- State management
- Type-safe interfaces
-
exception pepperpy.context.ContextError(message, details=None, cause=None)[source]
Bases: PepperpyError
Context-related errors.
- Parameters:
-
- Return type:
None
-
class pepperpy.context.State(value, metadata=<factory>)[source]
Bases: object
State information with metadata.
- Parameters:
-
-
value:
Any
-
metadata:
Dict[str, Any]
-
class pepperpy.context.Context(name='default', *, timeout=None, parent=None, data=None)[source]
Bases: Generic[T]
Context class for managing context values.
- Parameters:
-
-
__init__(name='default', *, timeout=None, parent=None, data=None)[source]
Initialize context.
- Parameters:
-
- Return type:
None
-
get_context()[source]
Get the current context value.
- Returns:
The current context value, or None if not set.
- Return type:
Optional[T]
-
set_context(value)[source]
Set the current context value.
- Parameters:
value (Optional[TypeVar(T)]) – The value to set
- Return type:
None
-
get(key, default=None)[source]
Get value from context.
- Parameters:
-
- Return type:
Optional[TypeVar(T)]
- Returns:
Value or default if not found
-
set(key, value)[source]
Set value in context.
- Parameters:
-
- Return type:
None
-
update(data)[source]
Update context with dictionary.
- Parameters:
data (Dict[str, Any]) – Dictionary of values to update
- Return type:
None
-
get_state()[source]
Get current state.
- Return type:
Optional[State]
- Returns:
Current state or None
-
set_state(value, **metadata)[source]
Set current state.
- Parameters:
-
- Return type:
None
-
chain(name)[source]
Create a new chained context.
- Parameters:
name (str) – Child context name
- Return type:
Context[TypeVar(T)]
- Returns:
New context with this as parent
-
async cancel()[source]
Cancel context operations.
- Return type:
None
-
property cancelled: bool
Check if context is cancelled.
- Returns:
True if context is cancelled
-
async wait_for_cancel()[source]
Wait for context cancellation.
- Return type:
None