Open ilanbiala opened 1 month ago
I think you'd have to do if isinstance(bus, KvaserBus)
or if hasattr(bus, "channel")
for this.
We should probably add a channel
property to BusABC
,
Yeah, generally I'd rather avoid conditionals to appease Mypy/Pylance, etc. I skimmed through the code and it does seem like BusABC
should have channel
and that member value could be instantiated by each interface implementation? Only hiccup is that it seems like each implementation could have a different type for channel
, e.g. SocketCAN expects channel
is a str
while Kvaser expects channel
is an int
.
Currently instantiating a bus looks something like:
However, then
bus.channel
is unknown because it is not defined incan.bus.BusABC
, butchannel
is a defined and used attributed in subclasses such asKvaserBus
andSocketcanBus
. Is there a more specific type that can be used, or something that exposes thechannel
argument provided when instantiating a CAN bus?