Skip to content

Commit 5f879c7

Browse files
committed
refactor: fix incorrect usage of Optional type hint
1 parent 00eea03 commit 5f879c7

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

nbswave/audio.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ def load_sound(path: str) -> AudioSegment:
1111

1212
def sync(
1313
sound: AudioSegment,
14-
channels: Optional[int] = 2,
15-
frame_rate: Optional[int] = 44100,
16-
sample_width: Optional[int] = 2,
14+
channels: int = 2,
15+
frame_rate: int = 44100,
16+
sample_width: int = 2,
1717
) -> AudioSegment:
1818
return (
1919
sound.set_channels(channels)
@@ -43,10 +43,10 @@ def vol_to_gain(vol: float) -> float:
4343
class Mixer:
4444
def __init__(
4545
self,
46-
sample_width: Optional[int] = 2,
47-
frame_rate: Optional[int] = 44100,
48-
channels: Optional[int] = 2,
49-
length: Optional[float] = 0,
46+
sample_width: int = 2,
47+
frame_rate: int = 44100,
48+
channels: int = 2,
49+
length: float = 0,
5050
):
5151
self.sample_width = sample_width
5252
self.frame_rate = frame_rate
@@ -102,7 +102,7 @@ def append(self, sound):
102102

103103
def to_audio_segment(self):
104104
peak = np.abs(self.output).max()
105-
clipping_factor = peak / (2 ** 15 - 1)
105+
clipping_factor = peak / (2**15 - 1)
106106

107107
if clipping_factor > 1:
108108
print(
@@ -141,11 +141,11 @@ def from_audio_segment(cls, segment: AudioSegment):
141141
def save(
142142
self,
143143
filename: str,
144-
format: Optional[str] = "wav",
145-
sample_width: Optional[int] = 2,
146-
frame_rate: Optional[int] = 44100,
147-
channels: Optional[int] = 2,
148-
target_bitrate: Optional[int] = 320,
144+
format: str = "wav",
145+
sample_width: int = 2,
146+
frame_rate: int = 44100,
147+
channels: int = 2,
148+
target_bitrate: int = 320,
149149
target_size: Optional[int] = None,
150150
tags: Optional[Dict[str, str]] = None,
151151
):

nbswave/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import os
33
import zipfile
4-
from typing import BinaryIO, Dict, Optional, Sequence, Union
4+
from typing import BinaryIO, Dict, Sequence, Union
55

66
import pydub
77
import pynbs
@@ -92,7 +92,7 @@ class SongRenderer:
9292
def __init__(
9393
self,
9494
song: Union[pynbs.File, nbs.Song],
95-
default_sound_path: Optional[PathLike] = SOUNDS_PATH,
95+
default_sound_path: PathLike = SOUNDS_PATH,
9696
):
9797
if isinstance(song, pynbs.File):
9898
song = nbs.Song(song)
@@ -135,9 +135,9 @@ def _mix(
135135
self,
136136
notes: Sequence[nbs.Note],
137137
ignore_missing_instruments: bool = False,
138-
sample_rate: Optional[int] = 44100,
139-
channels: Optional[int] = 2,
140-
bit_depth: Optional[int] = 16,
138+
sample_rate: int = 44100,
139+
channels: int = 2,
140+
bit_depth: int = 16,
141141
) -> audio.Track:
142142

143143
tempo_segments = self._song.tempo_segments

nbswave/nbs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ def layer_groups(self) -> Dict[str, pynbs.Layer]:
191191
groups[name].append(layer.id)
192192
return groups
193193

194-
def notes_by_layer(
195-
self, group_by_name: Optional[bool] = False
196-
) -> Dict[str, List[Note]]:
194+
def notes_by_layer(self, group_by_name: bool = False) -> Dict[str, List[Note]]:
197195
"""Return a dict of lists containing the weighted notes in each non-empty layer of the
198196
song. If `group_by_name` is true, notes in layers with identical names will be grouped."""
199197
groups = {}

0 commit comments

Comments
 (0)