diff --git a/ops/pebble.py b/ops/pebble.py index 35ad53c25..d065ef005 100644 --- a/ops/pebble.py +++ b/ops/pebble.py @@ -242,7 +242,7 @@ def connect(self, url: str, socket: socket.socket): ... # noqa def shutdown(self): ... # noqa def send(self, payload: str): ... # noqa def send_binary(self, payload: bytes): ... # noqa - def recv(self) -> typing.AnyStr: ... # noqa + def recv(self) -> Union[str, bytes]: ... # noqa logger = logging.getLogger(__name__) @@ -1411,7 +1411,7 @@ def _websocket_to_writer(ws: '_WebSocket', writer: '_WebsocketWriter', encoding: Optional[str]): """Receive messages from websocket (until end signal) and write to writer.""" while True: - chunk: Union[str, bytes] = typing.cast(Union[str, bytes], ws.recv()) + chunk = ws.recv() if isinstance(chunk, str): try: @@ -1474,7 +1474,7 @@ def read(self, n: int = -1) -> Union[str, bytes]: return b'' while not self.remaining: - chunk: Union[str, bytes] = typing.cast(Union[str, bytes], self.ws.recv()) + chunk = self.ws.recv() if isinstance(chunk, str): try: