Skip to content

Commit 0f7246c

Browse files
committed
feat: enhance type hinting in WokwiClientSync for improved clarity and consistency
1 parent b4194a8 commit 0f7246c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/wokwi_client/client_sync.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
from wokwi_client.serial import monitor_lines as monitor_serial_lines
1616

1717
if t.TYPE_CHECKING:
18-
from collections.abc import Iterable
18+
pass
1919

2020

2121
class WokwiClientSync:
2222
"""Synchronous wrapper around the async WokwiClient."""
2323

2424
token: str
25-
server: t.Optional[str]
26-
_loop: t.Optional[asyncio.AbstractEventLoop]
27-
_loop_thread: t.Optional[threading.Thread]
28-
_client: t.Optional[WokwiClient]
29-
_monitor_task: t.Optional[Future[t.Any]]
25+
server: str | None
26+
_loop: asyncio.AbstractEventLoop | None
27+
_loop_thread: threading.Thread | None
28+
_client: WokwiClient | None
29+
_monitor_task: Future[t.Any] | None
3030
_connected: bool
3131

32-
def __init__(self, token: str, server: t.Optional[str] = None) -> None:
32+
def __init__(self, token: str, server: str | None = None) -> None:
3333
self.token = token
3434
self.server = server
3535
self._loop = None
@@ -50,10 +50,12 @@ def _run_async(self, coro: t.Coroutine[t.Any, t.Any, t.Any], timeout: float = 30
5050
future = asyncio.run_coroutine_threadsafe(coro, self._loop)
5151
return future.result(timeout=timeout)
5252

53-
def connect(self) -> t.Dict[str, t.Any]:
53+
def connect(self) -> dict[str, t.Any]:
5454
if not self._connected:
5555
self._client = WokwiClient(self.token, self.server)
56-
result: t.Dict[str, t.Any] = t.cast(t.Dict[str, t.Any], self._run_async(self._client.connect()))
56+
result: dict[str, t.Any] = t.cast(
57+
dict[str, t.Any], self._run_async(self._client.connect())
58+
)
5759
self._connected = True
5860
return result
5961
return {}
@@ -85,7 +87,7 @@ def upload(self, name: str, content: bytes) -> t.Any:
8587
assert self._client is not None
8688
return self._run_async(self._client.upload(name, content))
8789

88-
def upload_file(self, filename: str, local_path: t.Optional[Path] = None) -> t.Any:
90+
def upload_file(self, filename: str, local_path: Path | None = None) -> t.Any:
8991
if not self._connected:
9092
raise RuntimeError("Client not connected")
9193
assert self._client is not None
@@ -94,9 +96,9 @@ def upload_file(self, filename: str, local_path: t.Optional[Path] = None) -> t.A
9496
def start_simulation(
9597
self,
9698
firmware: str,
97-
elf: t.Optional[str] = None,
99+
elf: str | None = None,
98100
pause: bool = False,
99-
chips: t.Optional[t.List[str]] = None,
101+
chips: list[str] | None = None,
100102
) -> t.Any:
101103
if not self._connected:
102104
raise RuntimeError("Client not connected")
@@ -109,7 +111,7 @@ def pause_simulation(self) -> t.Any:
109111
assert self._client is not None
110112
return self._run_async(self._client.pause_simulation())
111113

112-
def resume_simulation(self, pause_after: t.Optional[int] = None) -> t.Any:
114+
def resume_simulation(self, pause_after: int | None = None) -> t.Any:
113115
if not self._connected:
114116
raise RuntimeError("Client not connected")
115117
assert self._client is not None
@@ -133,7 +135,7 @@ def serial_monitor_cat(self) -> t.Any:
133135
assert self._client is not None
134136
return self._run_async(self._client.serial_monitor_cat())
135137

136-
def write_serial(self, data: t.Union[bytes, str, t.List[int]]) -> t.Any:
138+
def write_serial(self, data: bytes | str | list[int]) -> t.Any:
137139
if not self._connected:
138140
raise RuntimeError("Client not connected")
139141
assert self._client is not None
@@ -172,7 +174,7 @@ async def _monitor() -> None:
172174
assert self._loop is not None
173175
self._monitor_task = asyncio.run_coroutine_threadsafe(_monitor(), self._loop)
174176

175-
def set_control(self, part: str, control: str, value: t.Union[int, bool, float]) -> t.Any:
177+
def set_control(self, part: str, control: str, value: int | bool | float) -> t.Any:
176178
if not self._connected:
177179
raise RuntimeError("Client not connected")
178180
assert self._client is not None

0 commit comments

Comments
 (0)