component#
- component(cls=None, **default_params)[source]#
- Decorator for creating components with default parameters. - This decorator makes it easier to create components with parameters by: 1. Allowing default parameters to be specified at class definition time 2. Creating a factory function that can be used to create component instances 3. Preserving type hints and docstrings - Parameters:
- cls (Type[BaseComponent], optional) – The component class to decorate. If None, returns a decorator function. 
- **default_params – Default parameters to use when creating the component instance. 
 
- Returns:
- If cls is provided, returns a factory function for creating component instances. If cls is None, returns a decorator function. 
- Return type:
- Union[Type[BaseComponent], Callable] 
 - Examples - Basic usage: - >>> @component ... class MyComponent(BaseComponent): ... def __init__(self, model, verbose=False, param1=1, param2=2): ... super().__init__(model, verbose) ... self.param1 = param1 ... self.param2 = param2 - With default parameters: - >>> @component(param1=10, param2=20) ... class MyComponent(BaseComponent): ... def __init__(self, model, verbose=False, param1=1, param2=2): ... super().__init__(model, verbose) ... self.param1 = param1 ... self.param2 = param2 - Using the factory: - >>> # Create with default parameters >>> MyComponent.create(model) >>> # Create with custom parameters >>> MyComponent.create(model, param1=100, param2=200) 
