role#

bamengine.core.decorators.role(cls=None, *, name=None, **dataclass_kwargs)[source]#

Decorator to define a Role with automatic inheritance and dataclass.

This decorator dramatically simplifies Role definition by: 1. Making the class inherit from Role (if not already) 2. Applying @dataclass(slots=True) 3. Handling registration automatically

Parameters:
  • cls (type | None) – The class to decorate (provided automatically when used without parens)

  • name (str | None) – Optional custom name for the role. If None, uses the class name.

  • **dataclass_kwargs (Any) – Additional keyword arguments to pass to @dataclass. By default, slots=True is set.

Returns:

The decorated class or a decorator function

Return type:

type | Callable

Examples

Simplest usage (no inheritance needed):

>>> from bamengine.typing import Float
>>> @role
... class Producer:
...     price: Float
...     production: Float

With custom name:

>>> @role(name="MyProducer")
... class Producer:
...     price: Float
...     production: Float