DiamondLightSource / DiamondLightSource/dodal
collect_factories is incompatible with inner functions which instantiate devices
- Dominant language
- Python
- Stars
- 5
- Forks
- 13
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 10
Description
In the case that I have a function to instantiate my device class, and this function is called in my device factory,
```
class MyDevice(Device):
def __init__(self, prefix, name, my_param):
super().__init__()
# This function can be located in another file
def create_device_with_params(prefix, name) -> MyDevice:
return MyDevice(prefix, name, my_param=5)
# Then in ixx.py
@device_factory()
def my_device() -> MyDevice:
return create_device_with_params("", "")
```
,
dodal's `collect_factories` will identify both `my_device` and `create_device_with_params` as device factories. Then:
- `my_device` is correctly marked as type `DeviceInitializationController`
- `create_device_with_params` is not, since it wasn't defined with `@device_factory()` decorator
- `create_device_with_params` ends up being called with invalid kwargs on [this line](https://github.com/DiamondLightSource/dodal/blob/c7f3ae333571ee70b723dc1f801274f7c1a20bdb/src/dodal/utils.py#L332)
## Acceptance Criteria
* Implement fix
* Add unit test which fails before and passes after the fix
Contributor guide
Assessment
This issue has not been assessed yet.