From 30b1cc3a71b3c1a5021cd7e920d31e4399c366ed Mon Sep 17 00:00:00 2001 From: Chris Fiege Date: Sun, 3 Aug 2025 15:55:29 +0200 Subject: [PATCH] ConsoleProtocol: Update Signatures to match ConsoleExpectMixin The ConsoleExpectMixin has learned some new tricks over time. But the ConsoleProtocol was not updated accordingly. Every class implementing the ConsoleProtocol also uses the ConsoleExpectMixin - so it's safe to update the signatures according to the ConsoleExpectMixin. For ConsoleProtocol.expect() I've used the type definition of the underlying pexpect library. I have not updated the return types, since it's not clear to me what the ConsoleExpectMixin should return. Signed-off-by: Chris Fiege --- labgrid/protocol/consoleprotocol.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/labgrid/protocol/consoleprotocol.py b/labgrid/protocol/consoleprotocol.py index 3310813a1..70f18c95d 100644 --- a/labgrid/protocol/consoleprotocol.py +++ b/labgrid/protocol/consoleprotocol.py @@ -1,11 +1,14 @@ import abc +from typing import Optional + +from pexpect import EOF, TIMEOUT class ConsoleProtocol(abc.ABC): """Abstract class for the ConsoleProtocol""" @abc.abstractmethod - def read(self): + def read(self, size: int = 1, timeout: float = 0.0, max_size: Optional[int] = None): """ Read data from underlying port """ @@ -24,7 +27,11 @@ def sendline(self, line: str): def sendcontrol(self, char: str): raise NotImplementedError - def expect(self, pattern: str): + def expect( + self, + pattern: str | bytes | type[EOF] | type[TIMEOUT] | list[str | bytes | type[EOF] | type[TIMEOUT]], + timeout: float = -1, + ): raise NotImplementedError class Client(abc.ABC):