Remove argument `owner` in driver constructors
Description
The default constructor arguments for drivers are (from abstract base class Driver
):
def __init__(self,
name: str,
owner: "Optional[cosapp.systems.System]" = None,
**kwargs
) -> None:
In practice, argument owner
is never specified, and this interface is in contradiction with the normal way to create drivers, through System.add_driver
:
system = SomeSystem('system')
driver = system.add_driver(SomeDriver('driver')) # responsible for defining `system` as driver owner
Proposal 1: painless change
Simplify Driver.__init__
signature (and all other drivers accordingly) into:
def __init__(self, name: str, **kwargs) -> None:
This is harmless, as it will not affect System.add_driver
calls.
However, it does not address bug #42.
Notes
-
Driver
would still possess a getter and a setter method for attributeowner
, with type checking at assignment (value should be of typeSystem
). - The same logic is already implemented in class
BaseRecorder
: attributewatched_object
is not specified at construction; instead, it is set inDriver.add_recorder
.
Proposal 2: public API change
Keep Driver
ctor unchanged, remove Driver.owner
setter, and modify System.add_driver
interface, using pattern:
system.add_driver(SomeDriver, name='driver', **options) # pass class, and ctor args/kwargs
instead of
system.add_driver(SomeDriver('driver', **options)) # pass already built object
This modification would make explicit that users do not get to decide who the owner is, and will make System.add_driver
the only way to couple a system and a driver.
In particular, this will solve bug #42.
Edited by Etienne Lac