From 80fa7f5b8fcd715daec3755240a2a5d0269a461d Mon Sep 17 00:00:00 2001 From: Yaroslav Chvanov Date: Thu, 2 Mar 2023 04:59:20 +0300 Subject: [PATCH] Use 'key in dict' instead of 'key in dict.keys()' --- pyproject.toml | 3 +++ test/data-parse-test.py | 10 +++++----- tools/ratbagc.py.in | 6 +++--- tools/ratbagd.py | 14 +++++++------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fe3e0ed0..d1921f3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,9 @@ select = [ # pep8-naming # `Error` suffix on exception names. "N818", + # flake8-simplify + # Use 'key in dict' instead of 'key in dict.keys()'. + "SIM118", ] ignore = [ # Line too long. diff --git a/test/data-parse-test.py b/test/data-parse-test.py index 3c615e76..8fe613d3 100755 --- a/test/data-parse-test.py +++ b/test/data-parse-test.py @@ -72,7 +72,7 @@ def check_devicetype_str(string): def check_section_device(section: configparser.SectionProxy): required_keys = ["Name", "Driver", "DeviceMatch", "DeviceType"] - for key in section.keys(): + for key in section: assertIn(key, required_keys) for r in required_keys: @@ -131,7 +131,7 @@ def check_section_asus(section: configparser.SectionProxy): "Quirks", "Wireless", ) - for key in section.keys(): + for key in section: assertIn(key, permitted_keys) try: @@ -161,7 +161,7 @@ def check_section_hidpp10(section: configparser.SectionProxy): "DeviceIndex", "Leds", ] - for key in section.keys(): + for key in section: assertIn(key, permitted) try: @@ -210,7 +210,7 @@ def check_section_hidpp10(section: configparser.SectionProxy): def check_section_hidpp20(section: configparser.SectionProxy): permitted = ["Buttons", "DeviceIndex", "Leds", "ReportRate", "Quirk"] - for key in section.keys(): + for key in section: assertIn(key, permitted) try: @@ -231,7 +231,7 @@ def check_section_steelseries(section: configparser.SectionProxy): "MacroLength", "Quirk", ) - for key in section.keys(): + for key in section: assertIn(key, permitted_keys) try: diff --git a/tools/ratbagc.py.in b/tools/ratbagc.py.in index b1383b4d..1bf2f5ae 100644 --- a/tools/ratbagc.py.in +++ b/tools/ratbagc.py.in @@ -43,7 +43,7 @@ class MetaRatbag(type): except KeyError: pass else: - for k in libratbag.__dict__.keys(): + for k in libratbag.__dict__: if k.startswith(prefix) and k.isupper(): key = k[len(prefix) :] dct[key] = getattr(libratbag, k) @@ -215,7 +215,7 @@ class Ratbagd: else: self._devices[id] = dev - return self._devices[id] if id in self._devices.keys() else None + return self._devices[id] if id in self._devices else None def set_verbose(self, verbose): if verbose > 2: @@ -230,7 +230,7 @@ class Ratbagd: def get_capabilities(type, object): capabilities = [] - for k in libratbag.__dict__.keys(): + for k in libratbag.__dict__: if k.startswith(f"RATBAG_{type.upper()}_CAP_") and "CAP_NONE" not in k: cap = getattr(libratbag, k) func = getattr(libratbag, f"ratbag_{type.lower()}_has_capability") diff --git a/tools/ratbagd.py b/tools/ratbagd.py index 6c94af3d..d82a2ad0 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -282,7 +282,7 @@ class Ratbagd(_RatbagdDBus): self.emit("daemon-disappeared") def _on_properties_changed(self, proxy, changed_props, invalidated_props): - if "Devices" in changed_props.keys(): + if "Devices" in changed_props: object_paths = [d._object_path for d in self._devices] for object_path in changed_props["Devices"]: if object_path not in object_paths: @@ -452,14 +452,14 @@ class RatbagdProfile(_RatbagdDBus): self.notify("dirty") def _on_properties_changed(self, proxy, changed_props, invalidated_props): - if "IsActive" in changed_props.keys(): + if "IsActive" in changed_props: active = changed_props["IsActive"] if active != self._active: self._active = active self.notify("is-active") self._on_obj_notify(None, None) - if "ReportRate" in changed_props.keys(): + if "ReportRate" in changed_props: report_rate = changed_props["ReportRate"] if report_rate != self._report_rate: self._report_rate = report_rate @@ -619,19 +619,19 @@ class RatbagdResolution(_RatbagdDBus): self._disabled = self._get_dbus_property("IsDisabled") def _on_properties_changed(self, proxy, changed_props, invalidated_props): - if "IsActive" in changed_props.keys(): + if "IsActive" in changed_props: active = changed_props["IsActive"] if active != self._active: self._active = active self.notify("is-active") - if "IsDefault" in changed_props.keys(): + if "IsDefault" in changed_props: default = changed_props["IsDefault"] if default != self._default: self._default = default self.notify("is-default") - if "IsDisabled" in changed_props.keys(): + if "IsDisabled" in changed_props: disabled = changed_props["IsDisabled"] if disabled != self._disabled: self._disabled = disabled @@ -792,7 +792,7 @@ class RatbagdButton(_RatbagdDBus): super().__init__("Button", object_path) def _on_properties_changed(self, proxy, changed_props, invalidated_props): - if "Mapping" in changed_props.keys(): + if "Mapping" in changed_props: self.notify("action-type") def _mapping(self):