Skip to content

Commit acc90ad

Browse files
hunterhoganCopilot
andcommitted
add overload to blocks() and SoundFile.blocks()
Co-authored-by: Copilot <copilot@github.com>
1 parent e1069ab commit acc90ad

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

soundfile.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,32 @@ def write(file: FileDescriptorOrPath, data: AudioData, samplerate: int,
389389
compression_level, bitrate_mode) as f:
390390
f.write(data)
391391

392-
392+
@overload
393+
def blocks(file: FileDescriptorOrPath, blocksize: int | None = None,
394+
overlap: int = 0, frames: int = -1, start: int = 0,
395+
stop: int | None = None, dtype: dtype_str = 'float64',
396+
*, always_2d: Literal[True], fill_value: float | None = None,
397+
out: AudioData | None = None, samplerate: int | None = None,
398+
channels: int | None = None, format: str | None = None,
399+
subtype: str | None = None, endian: str | None = None,
400+
closefd: bool = True) -> Generator[AudioData_2d, None, None]: ...
401+
@overload
393402
def blocks(file: FileDescriptorOrPath, blocksize: int | None = None,
394403
overlap: int = 0, frames: int = -1, start: int = 0,
395404
stop: int | None = None, dtype: dtype_str = 'float64',
396405
always_2d: bool = False, fill_value: float | None = None,
397406
out: AudioData | None = None, samplerate: int | None = None,
398407
channels: int | None = None, format: str | None = None,
399408
subtype: str | None = None, endian: str | None = None,
400-
closefd: bool = True) -> Generator[AudioData, None, None]:
409+
closefd: bool = True) -> Generator[AudioData, None, None]: ...
410+
def blocks(file: FileDescriptorOrPath, blocksize: int | None = None,
411+
overlap: int = 0, frames: int = -1, start: int = 0,
412+
stop: int | None = None, dtype: dtype_str = 'float64',
413+
always_2d: bool = False, fill_value: float | None = None,
414+
out: AudioData | None = None, samplerate: int | None = None,
415+
channels: int | None = None, format: str | None = None,
416+
subtype: str | None = None, endian: str | None = None,
417+
closefd: bool = True) -> Generator[AudioData, None, None] | Generator[AudioData_2d, None, None]:
401418
"""Return a generator for block-wise reading.
402419
403420
By default, iteration starts at the beginning and stops at the end
@@ -1138,10 +1155,20 @@ def buffer_write(self, data: bytes, dtype: dtype_str) -> None:
11381155
assert written == frames
11391156
self._update_frames(written)
11401157

1158+
@overload
1159+
def blocks(self, blocksize: int | None = None, overlap: int = 0,
1160+
frames: int = -1, dtype: dtype_str = 'float64',
1161+
*, always_2d: Literal[True], fill_value: float | None = None,
1162+
out: AudioData | None = None) -> Generator[AudioData_2d, None, None]: ...
1163+
@overload
1164+
def blocks(self, blocksize: int | None = None, overlap: int = 0,
1165+
frames: int = -1, dtype: dtype_str = 'float64',
1166+
always_2d: bool = False, fill_value: float | None = None,
1167+
out: AudioData | None = None) -> Generator[AudioData, None, None]: ...
11411168
def blocks(self, blocksize: int | None = None, overlap: int = 0,
11421169
frames: int = -1, dtype: dtype_str = 'float64',
11431170
always_2d: bool = False, fill_value: float | None = None,
1144-
out: AudioData | None = None) -> Generator[AudioData, None, None]:
1171+
out: AudioData | None = None) -> Generator[AudioData, None, None] | Generator[AudioData_2d, None, None]:
11451172
"""Return a generator for block-wise reading.
11461173
11471174
By default, the generator yields blocks of the given

0 commit comments

Comments
 (0)