Skip to content

Commit 8af84da

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

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
@@ -390,15 +390,32 @@ def write(file: FileDescriptorOrPath, data: AudioData, samplerate: int,
390390
compression_level, bitrate_mode) as f:
391391
f.write(data)
392392

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

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

0 commit comments

Comments
 (0)