"""Function registry protocol for pluggable function lookup.
Allows applications to provide their own function registry implementation
without pyqt-reactor depending on specific function registry implementations.
"""
from typing import Protocol, Optional, Callable, Any, Dict
[docs]
class FunctionRegistryProtocol(Protocol):
"""Protocol for function registries that provide function lookup and metadata.
Applications can implement this protocol to provide their own function registry.
Example:
from pyqt_reactive.protocols import register_function_registry
from myapp.registry import MyFunctionRegistry
register_function_registry(MyFunctionRegistry())
"""
[docs]
def get_function_by_name(self, name: str) -> Optional[Callable]:
"""Get function by name.
Args:
name: Function name to lookup
Returns:
Function callable if found, None otherwise
"""
...
[docs]
def get_all_functions(self) -> Dict[str, Callable]:
"""Get all registered functions.
Returns:
Dictionary mapping function names to callables
"""
...
# Global registry instance (set by application)
_function_registry: Optional[FunctionRegistryProtocol] = None
[docs]
def register_function_registry(registry: FunctionRegistryProtocol) -> None:
"""Register a function registry implementation.
Args:
registry: Object implementing FunctionRegistryProtocol
"""
global _function_registry
_function_registry = registry
[docs]
def get_function_registry() -> Optional[FunctionRegistryProtocol]:
"""Get the registered function registry.
Returns:
Registered registry or None if not registered
"""
return _function_registry