Skip to content

Commit

Permalink
improved typing
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jan 23, 2025
1 parent 86652ba commit fb38052
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bs_rpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __new_call_id(self):
call_id += 1
return call_id

def call_for_response(self, body: Body) -> Body:
def call_for_response(self, body: Body) -> Body | None:
ch = Channel[Body]()
call_id = self.__new_call_id()
self.calls[call_id] = ch
Expand Down Expand Up @@ -99,7 +99,7 @@ def listen(self, context):
msg_parts = msg_buf.split(END_SECTION)

msg: Msg = json.loads(msg_parts[0])
#logging.info("[BsRpc] Received data: %s", msg)
# logging.info("[BsRpc] Received data: %s", msg)

body: Body = self.reg.get(msg["type"])(
data=msg["body"]
Expand Down
1 change: 1 addition & 0 deletions bs_rpc/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

T = TypeVar("T")


class Channel(Generic[T]):
def __init__(self):
self.__state: list[T] = []
Expand Down
1 change: 1 addition & 0 deletions bs_rpc/channel_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CloseFn = Callable[[], None]
T = TypeVar("T")


class ChannelGenerator(Generic[T]):
def __init__(self, ch: Channel[T], close_fn: CloseFn | None = None):
self.__ch: Channel[T] = ch
Expand Down
5 changes: 4 additions & 1 deletion bs_rpc/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

ResponseWriter = Callable[["Body"], None]


class Method(Enum):
CALL_FOR_RESPONSE = "call_for_response"
CALL_FOR_RESPONSES = "call_for_responses"
Expand All @@ -20,7 +21,9 @@ def call_for_response(self, context) -> "Body":
"""returns Body"""
raise Exception(f"call_for_response not implemented for {self.type}")

def call_for_responses(self, context, response_writer:ResponseWriter) -> None:
def call_for_responses(
self, context, response_writer: ResponseWriter
) -> None:
raise Exception(f"call_for_responses not implemented for {self.type}")

def get_type(self):
Expand Down
2 changes: 1 addition & 1 deletion pokete_classes/multiplayer/remote_fight/figure_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from typing_extensions import Generator
from typing import Generator

import bs_rpc
from pokete_classes.context import Context
Expand Down

0 comments on commit fb38052

Please sign in to comment.