Skip to content

Commit 38e0738

Browse files
committed
better type annotations for sending messages. Closes #171
1 parent a154b9e commit 38e0738

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

pythonosc/osc_message_builder.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
from pythonosc import osc_message
66
from pythonosc.parsing import osc_types
77

8-
ArgValue = Union[str, bytes, bool, int, float, osc_types.MidiPacket, list, None]
8+
# Represents a single OSC argument value.
9+
# Can be a primitive type, a MIDI packet, or a list/tuple for nested OSC arrays.
10+
ArgValue = Union[
11+
str, bytes, bool, int, float, osc_types.MidiPacket, List[Any], Tuple[Any, ...], None
12+
]
913

1014

1115
class BuildError(Exception):
@@ -193,7 +197,9 @@ def build(self) -> osc_message.OscMessage:
193197
raise BuildError(f"Could not build the message: {be}")
194198

195199

196-
def build_msg(address: str, value: ArgValue = "") -> osc_message.OscMessage:
200+
def build_msg(
201+
address: str, value: Union[ArgValue, Iterable[ArgValue]] = ""
202+
) -> osc_message.OscMessage:
197203
builder = OscMessageBuilder(address=address)
198204
values: Iterable[Any]
199205
if value == "":

pythonosc/tcp_client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import socket
55
import struct
6-
from typing import AsyncGenerator, Generator, List, Union
6+
from typing import AsyncGenerator, Generator, Iterable, List, Union
77

88
from pythonosc import slip
99
from pythonosc.dispatcher import Dispatcher
@@ -104,7 +104,9 @@ class SimpleTCPClient(TCPClient):
104104
def __init__(self, *args, **kwargs):
105105
super().__init__(*args, **kwargs)
106106

107-
def send_message(self, address: str, value: ArgValue = "") -> None:
107+
def send_message(
108+
self, address: str, value: Union[ArgValue, Iterable[ArgValue]] = ""
109+
) -> None:
108110
"""Build :class:`OscMessage` from arguments and send to server
109111
110112
Args:
@@ -251,7 +253,9 @@ def __init__(
251253
):
252254
super().__init__(address, port, family, mode)
253255

254-
async def send_message(self, address: str, value: ArgValue = "") -> None:
256+
async def send_message(
257+
self, address: str, value: Union[ArgValue, Iterable[ArgValue]] = ""
258+
) -> None:
255259
"""Build :class:`OscMessage` from arguments and send to server
256260
257261
Args:

pythonosc/udp_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def receive(self, timeout: int = 30) -> bytes:
9191
class SimpleUDPClient(UDPClient):
9292
"""Simple OSC client that automatically builds :class:`OscMessage` from arguments"""
9393

94-
def send_message(self, address: str, value: ArgValue) -> None:
94+
def send_message(
95+
self, address: str, value: Union[ArgValue, Iterable[ArgValue]]
96+
) -> None:
9597
"""Build :class:`OscMessage` from arguments and send to server
9698
9799
Args:

0 commit comments

Comments
 (0)