mini_arcade.utils.implementation_registry ========================================= .. py:module:: mini_arcade.utils.implementation_registry .. autoapi-nested-parse:: Typed, safe, and subclass-isolated implementation registry. Attributes ---------- .. autoapisummary:: mini_arcade.utils.implementation_registry.ImplementationType Classes ------- .. autoapisummary:: mini_arcade.utils.implementation_registry.ImplementationRegistry Module Contents --------------- .. py:data:: ImplementationType .. py:class:: ImplementationRegistry Bases: :py:obj:`Generic`\ [\ :py:obj:`ImplementationType`\ ] A registry of *classes* implementing a specific interface. Subclasses **must** set `implementation_base` to the ABC (or base class) that all implementations derive from. :ivar implementation_base: ClassVar[type]: The base class for registered implementations. :ivar _registry: ClassVar[MutableMapping[str, Type[ImplementationType]]]: Mapping of names to implementation classes. :ivar _lock: ClassVar[threading.RLock]: Lock for thread-safe operations. .. py:attribute:: implementation_base :type: ClassVar[type] .. py:method:: __init_subclass__(**kwargs) :classmethod: .. py:method:: register(name: str, impl_class: Type[ImplementationType], *, replace: bool = False) :classmethod: Register an implementation implementation class. :param name: Name to register the implementation under. :type name: str :param impl_class: Implementation class to register. :type impl_class: Type[ImplementationType] :param replace: Whether to replace an existing registration. :type replace: bool :raises TypeError: If `impl_class` does not subclass `implementation_base`. :raises KeyError: If `name` is already registered and `replace` is False .. py:method:: unregister(name: str) :classmethod: Unregister an implementation implementation by name. :param name: Name of the implementation to unregister. :type name: str .. py:method:: implementation(name: Optional[str] = None, *, replace: bool = False) -> Callable[[Type[ImplementationType]], Type[ImplementationType]] :classmethod: Decorator to register an implementation implementation class. :param name: Name to register the implementation under. :type name: Optional[str] :param replace: Whether to replace an existing registration. :type replace: bool .. py:method:: get(name: str) -> Type[ImplementationType] :classmethod: Get the implementation implementation class by name. :param name: Name of the implementation to retrieve. :type name: str :return: Implementation class. :rtype: Type[ImplementationType] :raises KeyError: If the name is not registered. .. py:method:: try_get(name: str) -> Optional[Type[ImplementationType]] :classmethod: Try to get the implementation implementation class by name. :param name: Name of the implementation to retrieve. :type name: str :return: Implementation class or None if not found. :rtype: Optional[Type[ImplementationType]] .. py:method:: contains(name: str) -> bool :classmethod: Check if an implementation implementation is registered by name. :param name: Name of the implementation to check. :type name: str :return: True if registered, False otherwise. :rtype: bool .. py:method:: all() -> Mapping[str, Type[ImplementationType]] :classmethod: Get a mapping of all registered implementation implementations. :return: Mapping of names to implementation classes. :rtype: Mapping[str, Type[ImplementationType]] .. py:method:: names() -> list[str] :classmethod: Get a list of all registered implementation implementation names. :return: List of implementation names. :rtype: list[str] .. py:method:: find_contains(needle: str) -> list[Type[ImplementationType]] :classmethod: Find all implementation implementations whose names contain the given substring (case-insensitive). :param needle: Substring to search for. :type needle: str :return: List of matching implementation classes. :rtype: list[Type[ImplementationType]] .. py:method:: find_regex(pattern: str) -> list[Type[ImplementationType]] :classmethod: Find all implementation implementations whose names match the given regex pattern (case-insensitive). :param pattern: Regex pattern to search for. :type pattern: str :return: List of matching implementation classes. :rtype: list[Type[ImplementationType]] .. py:method:: instantiate(name: str, *args, **kwargs) -> ImplementationType :classmethod: Instantiate an implementation implementation by name. :param name: Name of the implementation to instantiate. :type name: str :return: Instance of the implementation. :rtype: ImplementationType .. py:method:: clear() :classmethod: Clear all registered implementation implementations. .. py:method:: __iter__() -> Iterator[tuple[str, Type[ImplementationType]]] :classmethod: .. py:method:: __len__() -> int :classmethod: