Skip to content

Commit 6cb9342

Browse files
AvasamAlexWaygood
andauthored
Complete jack-client stub (#9530)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 242ef6f commit 6cb9342

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

stubs/JACK-Client/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version = "0.5.*"
2+
# Requires a version of numpy with a `py.typed` file
3+
requires = ["types-cffi", "numpy>=1.20"]
24

35
[tool.stubtest]
46
ignore_missing_stub = false

stubs/JACK-Client/jack/__init__.pyi

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
11
import sys
22
from _typeshed import Self
33
from collections.abc import Callable, Generator, Iterable, Iterator, Sequence
4-
from typing import Any, overload
5-
from typing_extensions import Literal, TypeAlias
4+
from typing import Any, NoReturn, overload
5+
from typing_extensions import Literal
66

7-
_NDArray: TypeAlias = Any # FIXME: no typings for numpy arrays
7+
import numpy
8+
from _cffi_backend import _CDataBase
9+
from numpy.typing import NDArray
810

9-
class _JackPositionT: ...
11+
# Aka jack_position_t
12+
# Actual type: _cffi_backend.__CDataOwn <cdata 'struct _jack_position *'>
13+
# This is not a real subclassing. Just ensuring type-checkers sees this type as compatible with _CDataBase
14+
# pyright has no error code for subclassing final
15+
class _JackPositionT(_CDataBase): # type: ignore[misc] # pyright: ignore
16+
audio_frames_per_video_frame: float
17+
bar: int
18+
bar_start_tick: float
19+
bbt_offset: int
20+
beat: int
21+
beat_type: float
22+
beats_per_bar: float
23+
beats_per_minute: float
24+
frame: int
25+
frame_rate: int
26+
frame_time: float
27+
next_time: float
28+
padding: _CDataBase # <cdata 'int32_t[7]'>
29+
tick: int
30+
ticks_per_beat: float
31+
unique_1: int
32+
unique_2: int
33+
usecs: int
34+
valid: int
35+
video_offset: int
1036

1137
class _CBufferType:
1238
@overload
@@ -100,9 +126,9 @@ class Client:
100126
@transport_frame.setter
101127
def transport_frame(self, frame: int) -> None: ...
102128
def transport_locate(self, frame: int) -> None: ...
103-
def transport_query(self) -> tuple[TransportState, dict[str, Any]]: ...
129+
def transport_query(self) -> tuple[TransportState, dict[str, Any]]: ... # Anyof[int, float, _CDataBase]
104130
def transport_query_struct(self) -> tuple[TransportState, _JackPositionT]: ...
105-
def transport_reposition_struct(self, position: _JackPositionT) -> None: ... # TODO
131+
def transport_reposition_struct(self, position: _JackPositionT) -> None: ...
106132
def set_sync_timeout(self, timeout: int) -> None: ...
107133
def set_freewheel(self, onoff: bool) -> None: ...
108134
def set_shutdown_callback(self, callback: Callable[[Status, str], object]) -> None: ...
@@ -149,7 +175,8 @@ class Client:
149175
def remove_all_properties(self) -> None: ...
150176

151177
class Port:
152-
def __init__(self, port_ptr: Any, client: Client) -> None: ...
178+
# <cdata 'struct _jack_port *'>
179+
def __init__(self, port_ptr: _CDataBase, client: Client) -> None: ...
153180
def __eq__(self, other: object) -> bool: ...
154181
def __ne__(self, other: object) -> bool: ...
155182
@property
@@ -196,12 +223,14 @@ class OwnPort(Port):
196223
def disconnect(self, other: str | Port | None = ...) -> None: ...
197224
def unregister(self) -> None: ...
198225
def get_buffer(self) -> _CBufferType: ...
199-
def get_array(self) -> _NDArray: ...
226+
def get_array(self) -> NDArray[numpy.float32]: ...
200227

201228
class OwnMidiPort(MidiPort, OwnPort):
202-
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
203-
def get_buffer(self) -> _CBufferType: ...
204-
def get_array(self) -> _NDArray: ...
229+
def __init__(self, port_ptr: _CDataBase, client: Client) -> None: ...
230+
# The implementation raises NotImplementedError, but this is not an abstract class.
231+
# `get_buffer()` and `get_array()` are disabled for OwnMidiPort
232+
def get_buffer(self) -> NoReturn: ...
233+
def get_array(self) -> NoReturn: ...
205234
@property
206235
def max_event_size(self) -> int: ...
207236
@property
@@ -212,7 +241,7 @@ class OwnMidiPort(MidiPort, OwnPort):
212241
def reserve_midi_event(self, time: int, size: int) -> _CBufferType: ...
213242

214243
class Ports:
215-
def __init__(self, client: Client, porttype: Any, flag: Any) -> None: ...
244+
def __init__(self, client: Client, porttype: str, flag: int) -> None: ...
216245
def __len__(self) -> int: ...
217246
def __getitem__(self, name: str) -> Port: ...
218247
def __iter__(self) -> Iterator[Port]: ...
@@ -278,7 +307,7 @@ class CallbackExit(Exception): ...
278307
def get_property(subject: int | str, key: str) -> tuple[bytes, str] | None: ...
279308
def get_properties(subject: int | str) -> dict[str, tuple[bytes, str]]: ...
280309
def get_all_properties() -> dict[str, dict[str, tuple[bytes, str]]]: ...
281-
def position2dict(pos: _JackPositionT) -> dict[str, Any]: ...
310+
def position2dict(pos: _JackPositionT) -> dict[str, Any]: ... # Anyof[int, float, _CDataBase]
282311
def version() -> tuple[int, int, int, int]: ...
283312
def version_string() -> str: ...
284313
def client_name_size() -> int: ...

0 commit comments

Comments
 (0)