Skip to content

Commit e5eff02

Browse files
committed
Add _InputStreamBase/_OutputStreamBase
... to avoid "incompatible override" warning from Pyright.
1 parent c4cc5eb commit e5eff02

File tree

1 file changed

+67
-55
lines changed

1 file changed

+67
-55
lines changed

sounddevice.py

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,45 +1165,8 @@ def close(self, ignore_errors=True):
11651165
_check(err, 'Error closing stream')
11661166

11671167

1168-
class RawInputStream(_StreamBase):
1169-
"""Raw stream for recording only. See __init__() and RawStream."""
1170-
1171-
def __init__(self, samplerate=None, blocksize=None,
1172-
device=None, channels=None, dtype=None, latency=None,
1173-
extra_settings=None, callback=None, finished_callback=None,
1174-
clip_off=None, dither_off=None, never_drop_input=None,
1175-
prime_output_buffers_using_stream_callback=None):
1176-
"""PortAudio input stream (using buffer objects).
1177-
1178-
This is the same as `InputStream`, except that the *callback*
1179-
function and `~RawStream.read()` work on plain Python buffer
1180-
objects instead of on NumPy arrays.
1181-
NumPy is not necessary for using this.
1182-
1183-
Parameters
1184-
----------
1185-
dtype : str
1186-
See `RawStream`.
1187-
callback : callable
1188-
User-supplied function to consume audio data in response to
1189-
requests from an active stream.
1190-
The callback must have this signature:
1191-
1192-
.. code-block:: text
1193-
1194-
callback(indata: buffer, frames: int,
1195-
time: CData, status: CallbackFlags) -> None
1196-
1197-
The arguments are the same as in the *callback* parameter of
1198-
`RawStream`, except that *outdata* is missing.
1199-
1200-
See Also
1201-
--------
1202-
RawStream, Stream
1203-
1204-
"""
1205-
_StreamBase.__init__(self, kind='input', wrap_callback='buffer',
1206-
**_remove_self(locals()))
1168+
class _InputStreamBase(_StreamBase):
1169+
"""Base class for input stream classes."""
12071170

12081171
@property
12091172
def read_available(self):
@@ -1215,7 +1178,7 @@ def read_available(self):
12151178
"""
12161179
return _check(_lib.Pa_GetStreamReadAvailable(self._ptr))
12171180

1218-
def read(self, frames):
1181+
def _raw_read(self, frames):
12191182
"""Read samples from the stream into a buffer.
12201183
12211184
This is the same as `Stream.read()`, except that it returns
@@ -1251,46 +1214,52 @@ def read(self, frames):
12511214
return _ffi.buffer(data), overflowed
12521215

12531216

1254-
class RawOutputStream(_StreamBase):
1255-
"""Raw stream for playback only. See __init__() and RawStream."""
1217+
class RawInputStream(_InputStreamBase):
1218+
"""Raw stream for recording only. See __init__() and RawStream."""
12561219

12571220
def __init__(self, samplerate=None, blocksize=None,
12581221
device=None, channels=None, dtype=None, latency=None,
12591222
extra_settings=None, callback=None, finished_callback=None,
12601223
clip_off=None, dither_off=None, never_drop_input=None,
12611224
prime_output_buffers_using_stream_callback=None):
1262-
"""PortAudio output stream (using buffer objects).
1225+
"""PortAudio input stream (using buffer objects).
12631226
1264-
This is the same as `OutputStream`, except that the *callback*
1265-
function and `~RawStream.write()` work on plain Python
1266-
buffer objects instead of on NumPy arrays.
1227+
This is the same as `InputStream`, except that the *callback*
1228+
function and `~RawStream.read()` work on plain Python buffer
1229+
objects instead of on NumPy arrays.
12671230
NumPy is not necessary for using this.
12681231
12691232
Parameters
12701233
----------
12711234
dtype : str
12721235
See `RawStream`.
12731236
callback : callable
1274-
User-supplied function to generate audio data in response to
1237+
User-supplied function to consume audio data in response to
12751238
requests from an active stream.
12761239
The callback must have this signature:
12771240
12781241
.. code-block:: text
12791242
1280-
callback(outdata: buffer, frames: int,
1243+
callback(indata: buffer, frames: int,
12811244
time: CData, status: CallbackFlags) -> None
12821245
12831246
The arguments are the same as in the *callback* parameter of
1284-
`RawStream`, except that *indata* is missing.
1247+
`RawStream`, except that *outdata* is missing.
12851248
12861249
See Also
12871250
--------
12881251
RawStream, Stream
12891252
12901253
"""
1291-
_StreamBase.__init__(self, kind='output', wrap_callback='buffer',
1254+
_StreamBase.__init__(self, kind='input', wrap_callback='buffer',
12921255
**_remove_self(locals()))
12931256

1257+
read = _InputStreamBase._raw_read
1258+
1259+
1260+
class _OutputStreamBase(_StreamBase):
1261+
"""Base class for output stream classes."""
1262+
12941263
@property
12951264
def write_available(self):
12961265
"""The number of frames that can be written without waiting.
@@ -1301,7 +1270,7 @@ def write_available(self):
13011270
"""
13021271
return _check(_lib.Pa_GetStreamWriteAvailable(self._ptr))
13031272

1304-
def write(self, data):
1273+
def _raw_write(self, data):
13051274
"""Write samples to the stream.
13061275
13071276
This is the same as `Stream.write()`, except that it expects
@@ -1348,6 +1317,49 @@ def write(self, data):
13481317
return underflowed
13491318

13501319

1320+
class RawOutputStream(_OutputStreamBase):
1321+
"""Raw stream for playback only. See __init__() and RawStream."""
1322+
1323+
def __init__(self, samplerate=None, blocksize=None,
1324+
device=None, channels=None, dtype=None, latency=None,
1325+
extra_settings=None, callback=None, finished_callback=None,
1326+
clip_off=None, dither_off=None, never_drop_input=None,
1327+
prime_output_buffers_using_stream_callback=None):
1328+
"""PortAudio output stream (using buffer objects).
1329+
1330+
This is the same as `OutputStream`, except that the *callback*
1331+
function and `~RawStream.write()` work on plain Python
1332+
buffer objects instead of on NumPy arrays.
1333+
NumPy is not necessary for using this.
1334+
1335+
Parameters
1336+
----------
1337+
dtype : str
1338+
See `RawStream`.
1339+
callback : callable
1340+
User-supplied function to generate audio data in response to
1341+
requests from an active stream.
1342+
The callback must have this signature:
1343+
1344+
.. code-block:: text
1345+
1346+
callback(outdata: buffer, frames: int,
1347+
time: CData, status: CallbackFlags) -> None
1348+
1349+
The arguments are the same as in the *callback* parameter of
1350+
`RawStream`, except that *indata* is missing.
1351+
1352+
See Also
1353+
--------
1354+
RawStream, Stream
1355+
1356+
"""
1357+
_StreamBase.__init__(self, kind='output', wrap_callback='buffer',
1358+
**_remove_self(locals()))
1359+
1360+
write = _OutputStreamBase._raw_write
1361+
1362+
13511363
class RawStream(RawInputStream, RawOutputStream):
13521364
"""Raw stream for playback and recording. See __init__()."""
13531365

@@ -1402,7 +1414,7 @@ def __init__(self, samplerate=None, blocksize=None,
14021414
**_remove_self(locals()))
14031415

14041416

1405-
class InputStream(RawInputStream):
1417+
class InputStream(_InputStreamBase):
14061418
"""Stream for input only. See __init__() and Stream."""
14071419

14081420
def __init__(self, samplerate=None, blocksize=None,
@@ -1472,12 +1484,12 @@ def read(self, frames):
14721484
"""
14731485
dtype, _ = _split(self._dtype)
14741486
channels, _ = _split(self._channels)
1475-
data, overflowed = RawInputStream.read(self, frames)
1487+
data, overflowed = _InputStreamBase._raw_read(self, frames)
14761488
data = _array(data, channels, dtype)
14771489
return data, overflowed
14781490

14791491

1480-
class OutputStream(RawOutputStream):
1492+
class OutputStream(_OutputStreamBase):
14811493
"""Stream for output only. See __init__() and Stream."""
14821494

14831495
def __init__(self, samplerate=None, blocksize=None,
@@ -1562,7 +1574,7 @@ def write(self, data):
15621574
data.dtype.name, dtype))
15631575
if not data.flags.c_contiguous:
15641576
raise TypeError('data must be C-contiguous')
1565-
return RawOutputStream.write(self, data)
1577+
return _OutputStreamBase._raw_write(self, data)
15661578

15671579

15681580
class Stream(InputStream, OutputStream):

0 commit comments

Comments
 (0)