beamlime.ProviderGroup#

class beamlime.ProviderGroup(*initial_providers)[source]#

Group of providers.

__init__(*initial_providers)[source]#

Initializes an empty internal provider dictionary and fills it with the initial providers from the argument.

Methods

__init__(*initial_providers)

Initializes an empty internal provider dictionary and fills it with the initial providers from the argument.

clear()

Clear all providers of this group.

items()

keys()

merge(*others)

Merge other provider groups into this group after checking conflicts.

pop(product_type)

Remove and return the provider of product_type.

provider([provider_call, provider_type])

Register the decorated callable into this group.

values()

__getitem__(product_type)[source]#

Return the provider of the requested product type.

Raises:

ProviderNotFoundError – If there is any providers for the requested product type.

Return type:

Provider[TypeVar(Product)]

clear()[source]#

Clear all providers of this group.

Return type:

None

merge(*others)[source]#

Merge other provider groups into this group after checking conflicts.

Return type:

None

pop(product_type)[source]#

Remove and return the provider of product_type. Return UnknownProvider if not found.

Return type:

Provider[TypeVar(Product)]

provider(provider_call=None, /, *, provider_type=None)[source]#

Register the decorated callable into this group. The product type will be retrieved from the annotation.

Return type:

Callable[[Callable[..., TypeVar(Product)] | type[TypeVar(Product)]], Callable[..., TypeVar(Product)] | type[TypeVar(Product)]] | Callable[..., TypeVar(Product)] | type[TypeVar(Product)]

Examples

>>> from beamlime import ProviderGroup
>>> from typing import Literal
>>> number_providers = ProviderGroup()
>>> @number_providers.provider
... def give_one() -> Literal[1]:
...   return 1
...
>>> number_providers[Literal[1]]() == 1
True