diff --git a/pyproject.toml b/pyproject.toml index 00a98bb9..8051504a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,8 @@ select = [ "B", # flake8-pie "PIE", + # flake8-return + "RET", # pep8-naming # `Error` suffix on exception names. "N818", diff --git a/tools/ratbagc.py.in b/tools/ratbagc.py.in index b442b871..ac393d05 100644 --- a/tools/ratbagc.py.in +++ b/tools/ratbagc.py.in @@ -168,14 +168,16 @@ class Ratbagd: v = libratbag.ratbag_log_get_priority(self._ratbag) if v == libratbag.RATBAG_LOG_PRIORITY_RAW: return 3 - elif v == libratbag.RATBAG_LOG_PRIORITY_DEBUG: # noqa: SIM114 + if v == libratbag.RATBAG_LOG_PRIORITY_DEBUG: # to match with setter action, we return 1 instead of 2 return 1 - elif v == libratbag.RATBAG_LOG_PRIORITY_INFO: + if v == libratbag.RATBAG_LOG_PRIORITY_INFO: return 1 - elif v == libratbag.RATBAG_LOG_PRIORITY_ERROR: + if v == libratbag.RATBAG_LOG_PRIORITY_ERROR: return 0 + return 0 + @verbose.setter def verbose(self, verbosity): if verbosity > 2: diff --git a/tools/ratbagctl.body.py.in b/tools/ratbagctl.body.py.in index e9254223..4bd69ed6 100755 --- a/tools/ratbagctl.body.py.in +++ b/tools/ratbagctl.body.py.in @@ -525,7 +525,7 @@ def func_report_rate_set(ratbagd: Ratbagd, args: argparse.Namespace) -> None: def func_angle_snapping_get(ratbagd: Ratbagd, args: argparse.Namespace) -> None: profile, _device = find_profile(ratbagd, args) if profile.angle_snapping == -1: - return None + return print(bool(profile.angle_snapping)) @@ -538,7 +538,7 @@ def func_angle_snapping_set(ratbagd: Ratbagd, args: argparse.Namespace) -> None: def func_debounce_get(ratbagd: Ratbagd, args: argparse.Namespace) -> None: profile, _device = find_profile(ratbagd, args) if profile.debounce == -1: - return None + return print(profile.debounce) @@ -1471,7 +1471,7 @@ class RatbagParser: self, input_string: List[str], ns: argparse.Namespace ) -> argparse.ArgumentParser: r = self._sub_parse(input_string, ns) - return r + return r # noqa: RET504 def print_help(self, group: Optional[str], prefix: str = "") -> None: if self.group is not None: diff --git a/tools/ratbagd.py b/tools/ratbagd.py index d82a2ad0..aa5eece6 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -238,11 +238,10 @@ class _RatbagdDBus(GObject.GObject): except GLib.Error as e: if e.code == Gio.IOErrorEnum.TIMED_OUT: raise RatbagdDBusTimeoutError(e.message) from e - else: - # Unrecognized error code; print the message to stderr and raise - # the GLib.Error. - print(e.message, file=sys.stderr) - raise + + # Unrecognized error code. + print(e.message, file=sys.stderr) + raise def __eq__(self, other): return other and self._object_path == other._object_path @@ -660,7 +659,8 @@ class RatbagdResolution(_RatbagdDBus): res = self._get_dbus_property("Resolution") if isinstance(res, int): res = tuple([res]) - return res + # False-positive RET504: + return res # noqa: RET504 @resolution.setter def resolution(self, resolution): diff --git a/tools/toolbox.py b/tools/toolbox.py index 158709e3..f5ea4f5e 100644 --- a/tools/toolbox.py +++ b/tools/toolbox.py @@ -46,12 +46,10 @@ def import_non_standard_path(name, path): # there's a problem we can't handle -- let the caller handle it. with open(path, "rb") as fp: - module = imp.load_module( + return imp.load_module( name, fp, os.path.basename(path), (".py", "rb", imp.PY_SOURCE) ) - return module - def start_ratbagd(verbosity=0): from gi.repository import Gio