pybricks.common.BLE: Improve typing for broadcast() and observe()

- Add overloads for broadcast(). It accepts either a single value, or a tuple,
  or a list.

- Adjust return type of observe(). It either returns a single value, or a tuple.
This commit is contained in:
Frederik Leonhardt
2026-05-28 11:12:17 +02:00
committed by Laurens Valk
parent 7411a246c9
commit 7014f46441
+21 -1
View File
@@ -1448,7 +1448,22 @@ class BLE:
.. versionadded:: 3.3
"""
@overload
def broadcast(
self, data: Iterable[Union[bool, int, float, str, bytes]]
) -> MaybeAwaitable:
...
@overload
def broadcast(self, data: Union[bool, int, float, str, bytes]) -> MaybeAwaitable:
...
def broadcast(
self,
data: Union[
Iterable[Union[bool, int, float, str, bytes]], bool, int, float, str, bytes
],
) -> MaybeAwaitable:
"""broadcast(data)
Starts broadcasting the given data on
@@ -1479,7 +1494,12 @@ class BLE:
def observe(
self, channel: int
) -> Optional[Tuple[Union[bool, int, float, str, bytes], ...]]:
) -> Optional[
Union[
Tuple[Union[bool, int, float, str, bytes], ...],
Union[bool, int, float, str, bytes],
]
]:
"""observe(channel) -> bool | int | float | str | bytes | tuple | None
Retrieves the last observed data for a given channel.