From 593da22073ca0aa5240878913c16910ac17bfe8a Mon Sep 17 00:00:00 2001 From: Bruce Merry Date: Thu, 21 Sep 2023 16:55:53 +0200 Subject: [PATCH] Fix type annotations for send.UdpStream constructors - Remove the old constructor which took a hostname and port (it was removed in spead2 4.0) - Ensure that buffer_size is correctly handled for all the constructors that use it. This required duplicating each overload to handle two cases: if the following required arguments are passed positionally then config and buffer_size are required; if they are passed as kwargs then config and buffer_size are optional. --- src/spead2/send/__init__.pyi | 40 +++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/spead2/send/__init__.pyi b/src/spead2/send/__init__.pyi index 7abd08324..a00936936 100644 --- a/src/spead2/send/__init__.pyi +++ b/src/spead2/send/__init__.pyi @@ -98,14 +98,28 @@ class SyncStream(Stream): class _UdpStream: DEFAULT_BUFFER_SIZE: ClassVar[int] + # There are a lot of overloads listed here, because the bindings have + # overloads where required arguments follow optional arguments, and that + # can't be represented in pure Python. So we have to distinguish the + # cases where the required arguments are specified by name versus + # position. @overload def __init__( self, thread_pool: spead2.ThreadPool, - socket: socket.socket, - hostname: str, - port: int, + endpoints: _EndpointList, config: StreamConfig = ..., + buffer_size: int = ..., + interface_address: str = ..., + ) -> None: ... + @overload + def __init__( + self, + thread_pool: spead2.ThreadPool, + endpoints: _EndpointList, + config: StreamConfig, + buffer_size: int, + ttl: int, ) -> None: ... @overload def __init__( @@ -114,7 +128,8 @@ class _UdpStream: endpoints: _EndpointList, config: StreamConfig = ..., buffer_size: int = ..., - interface_address: str = ..., + *, + ttl: int, ) -> None: ... @overload def __init__( @@ -124,13 +139,16 @@ class _UdpStream: config: StreamConfig, buffer_size: int, ttl: int, + interface_address: str, ) -> None: ... @overload def __init__( self, thread_pool: spead2.ThreadPool, endpoints: _EndpointList, - config: StreamConfig, + config: StreamConfig = ..., + buffer_size: int = ..., + *, ttl: int, interface_address: str, ) -> None: ... @@ -140,6 +158,18 @@ class _UdpStream: thread_pool: spead2.ThreadPool, endpoints: _EndpointList, config: StreamConfig, + buffer_size: int, + ttl: int, + interface_index: int, + ) -> None: ... + @overload + def __init__( + self, + thread_pool: spead2.ThreadPool, + endpoints: _EndpointList, + config: StreamConfig = ..., + buffer_size: int = ..., + *, ttl: int, interface_index: int, ) -> None: ...