Skip to content

Commit

Permalink
Fix pyright issues and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed Sep 7, 2024
1 parent e804381 commit ea50807
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
13 changes: 6 additions & 7 deletions collegamento/client_server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
>>> def test(*args):
... return
>>> c = Client({"test": (test, True)})
>>> c.request({"command": "test"})
>>> c.request({"command": "test"})
>>> c.request("test")
>>> c.request("test")
>>> from time import sleep
>>> sleep(1)
>>> res = c.get_response("test")
Expand Down Expand Up @@ -36,7 +36,7 @@ class Client:
The public API includes the following methods:
- Client.add_command(name: str, command: USER_FUNCTION, multiple_requests: bool = False)
- Client.request(request_details: dict) -> None | int
- Client.request(command: str, **kwargs) -> None | int
- Client.get_response(command: str) -> Response | list[Response] | None
- Client.kill_IPC()
"""
Expand Down Expand Up @@ -107,7 +107,8 @@ def create_message_id(self) -> int:

# In cases where there are many many requests being sent it may be faster to choose a
# random id than to iterate through the list of id's and find an unclaimed one
id: int = randint(1, self.id_max) # 0 is reserved for the empty case
# NOTE: 0 is reserved for when there's no curent id's (self.current_ids)
id: int = randint(1, self.id_max)
while id in self.all_ids:
id = randint(1, self.id_max)
self.all_ids.append(id)
Expand Down Expand Up @@ -185,9 +186,7 @@ def get_response(self, command: str) -> Response | list[Response] | None:

# If we know that the command doesn't allow multiple requests don't give a list
if not self.commands[command][1]:
return response[
0
] # Will only ever be one but we know its at index 0
return response[0] # Will only ever be one

return response

Expand Down
7 changes: 1 addition & 6 deletions collegamento/client_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ def run_tasks(self) -> None:
for request in request_list
]

requests_list = sorted(
requests_list,
key=lambda request: command_sort_func(
request, self.priority_commands
),
)
requests_list = sorted(requests_list, key=lambda request: command_sort_func(request, self.priority_commands))

for request in requests_list:
if request is None:
Expand Down
12 changes: 6 additions & 6 deletions collegamento/client_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class CollegamentoError(Exception): ... # I don't like the boilerplate either
] # if bool is true the command allows multiple requests


ResponseQueueType = GenericQueueClass
RequestQueueType = GenericQueueClass

# "If this is CPython < 3.12. We are now in the No Man's Land
# of Typing. In this case, avoid subscripting "GenericQueue". Ugh."
# - @leycec, maintainer of the amazing @beartype
if TYPE_CHECKING:
ResponseQueueType = GenericQueueClass[Response]
RequestQueueType = GenericQueueClass[Request]
# "Else this is CPython < 3.12. We are now in the No Man's Land
# of Typing. In this case, avoid subscripting "GenericQueue". Ugh."
# - @leycec, maintainer of the amazing @beartype
else:
ResponseQueueType = GenericQueueClass
RequestQueueType = GenericQueueClass

0 comments on commit ea50807

Please sign in to comment.