Skip to content

Commit 56409e7

Browse files
authored
Replace typing.AnyStr with Union[str, bytes]
Hi! While working on python/mypy#15732 our tools detected a misuse of `AnyStr` TypeVar (which is quite common). The proper way is to use `Union` here :)
1 parent a3b110e commit 56409e7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ops/pebble.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def connect(self, url: str, socket: socket.socket): ... # noqa
242242
def shutdown(self): ... # noqa
243243
def send(self, payload: str): ... # noqa
244244
def send_binary(self, payload: bytes): ... # noqa
245-
def recv(self) -> typing.AnyStr: ... # noqa
245+
def recv(self) -> Union[str, bytes]: ... # noqa
246246

247247
logger = logging.getLogger(__name__)
248248

@@ -1411,7 +1411,7 @@ def _websocket_to_writer(ws: '_WebSocket', writer: '_WebsocketWriter',
14111411
encoding: Optional[str]):
14121412
"""Receive messages from websocket (until end signal) and write to writer."""
14131413
while True:
1414-
chunk: Union[str, bytes] = typing.cast(Union[str, bytes], ws.recv())
1414+
chunk = ws.recv()
14151415

14161416
if isinstance(chunk, str):
14171417
try:
@@ -1474,7 +1474,7 @@ def read(self, n: int = -1) -> Union[str, bytes]:
14741474
return b''
14751475

14761476
while not self.remaining:
1477-
chunk: Union[str, bytes] = typing.cast(Union[str, bytes], self.ws.recv())
1477+
chunk = self.ws.recv()
14781478

14791479
if isinstance(chunk, str):
14801480
try:

0 commit comments

Comments
 (0)