hutcheb commented on PR #348:
URL: https://github.com/apache/plc4x/pull/348#issuecomment-1097232038
So I've ended up with abstract class such as this which allow you to pass
return types, in this case it goes 3 or 4 deep before I create a concrete
class. It seems to work but feels a bit clunky when I assigning multiple
TypeVar's.
Just looking for opinions :)
`T = TypeVar("T", bound=PlcResponse)
class PlcRequest(Generic[T], ABC):
"""
Base type for all messages sent from the plc4x system to a connected plc.
"""
@abstractmethod
def execute(self) -> Future[T]:
pass
U = TypeVar("U", bound=PlcFieldResponse)
class PlcFieldRequest(PlcRequest[U]):
def __init__(self, fields: list[PlcField] = []):
self.fields = fields
@abstractmethod
def execute(self) -> Future[U]:
pass
@property
def field_names(self):
return [field.name for field in self.fields]`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]