Skip to content

Commit

Permalink
Replace typing.AnyStr with Union[str, bytes] (#978)
Browse files Browse the repository at this point in the history
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 :)
  • Loading branch information
sobolevn committed Jul 24, 2023
1 parent a3b110e commit 2c82af3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2c82af3

Please sign in to comment.