Skip to content

Commit 47d46cb

Browse files
committed
ruff
1 parent b518e68 commit 47d46cb

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

examples/rpc.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def main():
5555
await asyncio.create_task(perform_long_calculation(callers_room))
5656
except Exception as error:
5757
print("Error:", error)
58-
58+
5959
try:
6060
print("\n\nRunning long calculation with disconnect...")
6161
# Start the long calculation
@@ -82,7 +82,9 @@ async def main():
8282
finally:
8383
# Clean up all rooms
8484
print("Disconnecting all participants...")
85-
await asyncio.gather(*(room.disconnect() for room in rooms), return_exceptions=True)
85+
await asyncio.gather(
86+
*(room.disconnect() for room in rooms), return_exceptions=True
87+
)
8688
print("Cleanup complete")
8789

8890

@@ -143,7 +145,9 @@ async def long_calculation_method(
143145
response_timeout: float,
144146
):
145147
print(f"[Math Genius] Starting a very long calculation for {caller_identity}")
146-
print(f"[Math Genius] This will take 30 seconds even though you're only giving me {response_timeout} seconds")
148+
print(
149+
f"[Math Genius] This will take 30 seconds even though you're only giving me {response_timeout} seconds"
150+
)
147151
await asyncio.sleep(30)
148152
return json.dumps({"result": "Calculation complete!"})
149153

@@ -152,9 +156,7 @@ async def perform_greeting(room: rtc.Room):
152156
print("[Caller] Letting the greeter know that I've arrived")
153157
try:
154158
response = await room.local_participant.perform_rpc(
155-
destination_identity="greeter",
156-
method="arrival",
157-
payload="Hello"
159+
destination_identity="greeter", method="arrival", payload="Hello"
158160
)
159161
print(f'[Caller] That\'s nice, the greeter said: "{response}"')
160162
except Exception as error:
@@ -168,7 +170,7 @@ async def perform_square_root(room: rtc.Room):
168170
response = await room.local_participant.perform_rpc(
169171
destination_identity="math-genius",
170172
method="square-root",
171-
payload=json.dumps({"number": 16})
173+
payload=json.dumps({"number": 16}),
172174
)
173175
parsed_response = json.loads(response)
174176
print(f"[Caller] Nice, the answer was {parsed_response['result']}")
@@ -183,7 +185,7 @@ async def perform_quantum_hypergeometric_series(room: rtc.Room):
183185
response = await room.local_participant.perform_rpc(
184186
destination_identity="math-genius",
185187
method="quantum-hypergeometric-series",
186-
payload=json.dumps({"number": 42})
188+
payload=json.dumps({"number": 42}),
187189
)
188190
parsed_response = json.loads(response)
189191
print(f"[Caller] genius says {parsed_response['result']}!")
@@ -204,7 +206,7 @@ async def perform_divide(room: rtc.Room):
204206
response = await room.local_participant.perform_rpc(
205207
destination_identity="math-genius",
206208
method="divide",
207-
payload=json.dumps({"dividend": 10, "divisor": 0})
209+
payload=json.dumps({"dividend": 10, "divisor": 0}),
208210
)
209211
parsed_response = json.loads(response)
210212
print(f"[Caller] The result is {parsed_response['result']}")
@@ -226,7 +228,7 @@ async def perform_long_calculation(room: rtc.Room):
226228
destination_identity="math-genius",
227229
method="long-calculation",
228230
payload=json.dumps({}),
229-
response_timeout=10
231+
response_timeout=10,
230232
)
231233
parsed_response = json.loads(response)
232234
print(f"[Caller] Result: {parsed_response['result']}")

livekit-rtc/livekit/rtc/participant.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class PublishTranscriptionError(Exception):
6565
def __init__(self, message: str) -> None:
6666
self.message = message
6767

68+
6869
class Participant(ABC):
6970
def __init__(self, owned_info: proto_participant.OwnedParticipant) -> None:
7071
self._info = owned_info.info
@@ -391,6 +392,7 @@ async def _handle_rpc_method_invocation(
391392
else:
392393
try:
393394
if asyncio.iscoroutinefunction(handler):
395+
394396
async def run_handler():
395397
try:
396398
return await handler(
@@ -401,11 +403,15 @@ async def run_handler():
401403
raise
402404

403405
try:
404-
response_payload = await asyncio.wait_for(run_handler(), timeout=response_timeout)
406+
response_payload = await asyncio.wait_for(
407+
run_handler(), timeout=response_timeout
408+
)
405409
except asyncio.TimeoutError:
406410
raise RpcError._built_in(RpcError.ErrorCode.RESPONSE_TIMEOUT)
407411
except asyncio.CancelledError:
408-
raise RpcError._built_in(RpcError.ErrorCode.RECIPIENT_DISCONNECTED)
412+
raise RpcError._built_in(
413+
RpcError.ErrorCode.RECIPIENT_DISCONNECTED
414+
)
409415
else:
410416
response_payload = handler(
411417
request_id, caller_identity, payload, response_timeout
@@ -601,7 +607,3 @@ def track_publications(self) -> Mapping[str, RemoteTrackPublication]:
601607

602608
def __repr__(self) -> str:
603609
return f"rtc.RemoteParticipant(sid={self.sid}, identity={self.identity}, name={self.name})"
604-
605-
606-
607-

livekit-rtc/livekit/rtc/room.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ async def disconnect(self) -> None:
400400
"""Disconnects from the room."""
401401
if not self.isconnected():
402402
return
403-
403+
404404
if self._rpc_invocation_tasks:
405405
for task in self._rpc_invocation_tasks:
406406
task.cancel()
@@ -736,8 +736,3 @@ def __repr__(self) -> str:
736736
sid = self._first_sid_future.result()
737737

738738
return f"rtc.Room(sid={sid}, name={self.name}, metadata={self.metadata}, connection_state={self._connection_state})"
739-
740-
741-
742-
743-

0 commit comments

Comments
 (0)