Skip to content

Commit

Permalink
fix callbacks when destination is iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
circuitsacul committed Sep 8, 2022
1 parent 037238a commit 1943459
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions hikari_clusters/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import asyncio
from contextlib import contextmanager
from typing import TYPE_CHECKING, Generator, Iterable
from typing import TYPE_CHECKING, Collection, Generator

from . import payload

Expand Down Expand Up @@ -55,7 +55,7 @@ class Callback:

__slots__ = ("ipc", "key", "responders", "resps", "future")

def __init__(self, ipc: IpcClient, key: int, responders: Iterable[int]):
def __init__(self, ipc: IpcClient, key: int, responders: Collection[int]):
self.ipc = ipc
self.key = key
self.responders = responders
Expand All @@ -77,8 +77,7 @@ async def wait(self, timeout: float = 3.0) -> None:
self.resps[uid] = NoResponse()

def _get_missing(self) -> set[int]:
responded = self.resps.keys()
return {uid for uid in self.responders if uid not in responded}
return {uid for uid in self.responders if uid not in self.resps}

def _handle_response(self, pl: payload.RESPONSE) -> None:
self.resps[pl.author] = pl
Expand Down Expand Up @@ -136,7 +135,7 @@ def handle_response(self, pl: payload.RESPONSE) -> None:

@contextmanager
def callback(
self, responders: Iterable[int]
self, responders: Collection[int]
) -> Generator[Callback, None, None]:
"""Context manager for easy callback managing.
Expand Down
8 changes: 4 additions & 4 deletions hikari_clusters/ipc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import logging
import pathlib
import ssl
from typing import Any, Iterable, TypeVar, Union, cast
from typing import Any, Collection, Iterable, TypeVar, Union, cast

from websockets.exceptions import ConnectionClosed, ConnectionClosedOK
from websockets.legacy import client
Expand All @@ -49,8 +49,8 @@
_TO = Union[Iterable[Union[BaseInfo, int]], BaseInfo, int]


def _parse_to(to: _TO) -> Iterable[int]:
return map(int, to) if isinstance(to, Iterable) else [int(to)]
def _parse_to(to: _TO) -> set[int]:
return set(map(int, to)) if isinstance(to, Iterable) else {int(to)}


class IpcClient(IpcBase):
Expand Down Expand Up @@ -365,7 +365,7 @@ async def _handle_message(self, data: dict[str, Any]) -> None:
self.callbacks.handle_response(pl)

async def _send(
self, to: Iterable[int], pl_data: payload.PAYLOAD_DATA
self, to: Collection[int], pl_data: payload.PAYLOAD_DATA
) -> None:
assert self.uid is not None
pl = payload.Payload(
Expand Down

0 comments on commit 1943459

Please sign in to comment.