From 1b75d53cfbf2ee142fb05f9ce4ba9ddc5efe0767 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Mon, 4 Jul 2022 16:02:56 +0100 Subject: [PATCH] remove type checks. prefer duck typing --- voicemeeterlib/bus.py | 14 +------------- voicemeeterlib/command.py | 4 ---- voicemeeterlib/macrobutton.py | 6 ------ voicemeeterlib/meta.py | 4 ---- voicemeeterlib/recorder.py | 2 -- voicemeeterlib/strip.py | 14 +------------- voicemeeterlib/vban.py | 2 -- 7 files changed, 2 insertions(+), 44 deletions(-) diff --git a/voicemeeterlib/bus.py b/voicemeeterlib/bus.py index 38f7054..6005f06 100644 --- a/voicemeeterlib/bus.py +++ b/voicemeeterlib/bus.py @@ -29,8 +29,6 @@ class Bus(IRemote): @mute.setter def mute(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("mute is a boolean parameter") self.setter("mute", 1 if val else 0) @property @@ -39,8 +37,6 @@ class Bus(IRemote): @mono.setter def mono(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("mono is a boolean parameter") self.setter("mono", 1 if val else 0) @property @@ -49,8 +45,6 @@ class Bus(IRemote): @eq.setter def eq(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("eq is a boolean parameter") self.setter("eq.On", 1 if val else 0) @property @@ -59,8 +53,6 @@ class Bus(IRemote): @eq_ab.setter def eq_ab(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("eq_ab is a boolean parameter") self.setter("eq.ab", 1 if val else 0) @property @@ -69,8 +61,6 @@ class Bus(IRemote): @sel.setter def sel(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("sel is a boolean parameter") self.setter("sel", 1 if val else 0) @property @@ -79,9 +69,7 @@ class Bus(IRemote): @label.setter def label(self, val: str): - if not isinstance(val, str): - raise VMError("label is a string parameter") - self.setter("Label", val) + self.setter("Label", str(val)) @property def gain(self) -> float: diff --git a/voicemeeterlib/command.py b/voicemeeterlib/command.py index 52c1424..1914663 100644 --- a/voicemeeterlib/command.py +++ b/voicemeeterlib/command.py @@ -38,15 +38,11 @@ class Command(IRemote): return "Command" def set_showvbanchat(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("showvbanchat is a boolean parameter") self.setter("DialogShow.VBANCHAT", 1 if val else 0) showvbanchat = property(fset=set_showvbanchat) def set_lock(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("lock is a boolean parameter") self.setter("lock", 1 if val else 0) lock = property(fset=set_lock) diff --git a/voicemeeterlib/macrobutton.py b/voicemeeterlib/macrobutton.py index 576ad1c..716c1f1 100644 --- a/voicemeeterlib/macrobutton.py +++ b/voicemeeterlib/macrobutton.py @@ -27,8 +27,6 @@ class MacroButton(Adapter): @state.setter def state(self, val): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("state is a boolean parameter") self.setter(1 if val else 0, 1) @property @@ -37,8 +35,6 @@ class MacroButton(Adapter): @stateonly.setter def stateonly(self, val): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("stateonly is a boolean parameter") self.setter(1 if val else 0, 2) @property @@ -47,6 +43,4 @@ class MacroButton(Adapter): @trigger.setter def trigger(self, val): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("trigger is a boolean parameter") self.setter(1 if val else 0, 3) diff --git a/voicemeeterlib/meta.py b/voicemeeterlib/meta.py index e45ccb0..9cd6725 100644 --- a/voicemeeterlib/meta.py +++ b/voicemeeterlib/meta.py @@ -8,8 +8,6 @@ def bool_prop(param): return self.getter(param) == 1 def fset(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError(f"{param} is a boolean parameter") self.setter(param, 1 if val else 0) return property(fget, fset) @@ -44,8 +42,6 @@ def bus_mode_prop(param): return self.getter(param) == 1 def fset(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError(f"{param} is a boolean parameter") self.setter(param, 1 if val else 0) return property(fget, fset) diff --git a/voicemeeterlib/recorder.py b/voicemeeterlib/recorder.py index e535994..4752d73 100644 --- a/voicemeeterlib/recorder.py +++ b/voicemeeterlib/recorder.py @@ -53,8 +53,6 @@ class Recorder(IRemote): raise VMError("File full directory must be a raw string") def set_loop(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("Error True or False expected") self.setter("mode.loop", 1 if val else 0) loop = property(fset=set_loop) diff --git a/voicemeeterlib/strip.py b/voicemeeterlib/strip.py index 75c5c1c..167085c 100644 --- a/voicemeeterlib/strip.py +++ b/voicemeeterlib/strip.py @@ -30,8 +30,6 @@ class Strip(IRemote): @mono.setter def mono(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("mono is a boolean parameter") self.setter("mono", 1 if val else 0) @property @@ -40,8 +38,6 @@ class Strip(IRemote): @solo.setter def solo(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("solo is a boolean parameter") self.setter("solo", 1 if val else 0) @property @@ -50,8 +46,6 @@ class Strip(IRemote): @mute.setter def mute(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("mute is a boolean parameter") self.setter("mute", 1 if val else 0) @property @@ -68,9 +62,7 @@ class Strip(IRemote): @label.setter def label(self, val: str): - if not isinstance(val, str): - raise VMError("label is a string parameter") - self.setter("Label", val) + self.setter("Label", str(val)) @property def gain(self) -> float: @@ -136,8 +128,6 @@ class VirtualStrip(Strip): @mc.setter def mc(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("mc is a boolean parameter") self.setter("mc", 1 if val else 0) mono = mc @@ -180,8 +170,6 @@ class VirtualStrip(Strip): self.setter("AppGain", f'("{name}", {gain})') def appmute(self, name: str, mute: bool = None): - if not isinstance(mute, bool) and mute not in (0, 1): - raise VMError("appmute is a boolean parameter") self.setter("AppMute", f'("{name}", {1 if mute else 0})') diff --git a/voicemeeterlib/vban.py b/voicemeeterlib/vban.py index ab0e046..7f929d9 100644 --- a/voicemeeterlib/vban.py +++ b/voicemeeterlib/vban.py @@ -25,8 +25,6 @@ class VbanStream(IRemote): @on.setter def on(self, val: bool): - if not isinstance(val, bool) and val not in (0, 1): - raise VMError("True or False expected") self.setter("on", 1 if val else 0) @property