Skip to content

Commit

Permalink
style(ruff): enable PERF
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Jun 21, 2024
1 parent ec12ee6 commit b639c33
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion oomox_gui/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def hex_to_int(text: "HexColor") -> int:
return int(f"0x{text}", 0)


def int_to_hex(num: int | float) -> "HexColor":
def int_to_hex(num: float) -> "HexColor":
return f"{int(num):02x}"


Expand Down
11 changes: 6 additions & 5 deletions oomox_gui/gtk_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,15 @@ def __init__(cls, name: str, transient_for: Gtk.Window, data: "Any") -> None:
)
):
required_methods = getattr(cls, cls.ABS_METHODS, [])
missing_methods = []
for method_name in required_methods:
missing_methods = [
method_name
for method_name in required_methods
if (
not any(method_name in B.__dict__ for B in cls.__mro__)
not any(method_name in B.__dict__ for B in cls.__mro__)
) and (
method_name not in this_required_methods
):
missing_methods.append(method_name)
)
]
if missing_methods:
missing_methods_error = (
f"Can't instantiate abstract class {cls.__name__}"
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/multi_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def on_preset_changed(self, widget: Gtk.ComboBox) -> None:
config_name=f"{CONFIG_FILE_PREFIX}{self.current_preset}",
force_reload=True,
)
for _idx, data in self.config.config.items():
for data in self.config.config.values():
plugin_name = data.get("name")
plugin_config = data.get("config")
if plugin_name and plugin_config:
Expand Down
2 changes: 1 addition & 1 deletion oomox_gui/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def init_plugins(cls) -> None:
for plugin_name, plugin_path in all_plugin_paths.items():
try:
cls.load_plugin(plugin_name, plugin_path)
except Exception as exc:
except Exception as exc: # noqa: PERF203
message_header = translate('Error loading plugin "{plugin_name}"').format(
plugin_name=plugin_name,
)
Expand Down
17 changes: 9 additions & 8 deletions oomox_gui/preset_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from collections import namedtuple
from typing import TYPE_CHECKING, overload
from typing import TYPE_CHECKING, NamedTuple, overload

from gi.repository import Gdk, GLib, Gtk

Expand All @@ -19,7 +18,9 @@
from .theme_file import PresetFile


Section = namedtuple("Section", ["id", "display_name"])
class Section(NamedTuple):
name: str
display_name: str


class Sections:
Expand Down Expand Up @@ -171,7 +172,7 @@ def _focus_preset_by_treepath(self, treepath: Gtk.TreePath) -> None:
try:
self.treestore.get_iter(treepath)
path_found = True
except ValueError:
except ValueError: # noqa: PERF203
treepath.prev()
self.treeview.expand_to_path(treepath) # type: ignore[arg-type]
self.treeview.set_cursor(treepath)
Expand Down Expand Up @@ -225,7 +226,7 @@ def _add_section(
) -> Gtk.TreeIter:
return self._add_directory(
template="<b>{}</b>", name=section.display_name,
parent=parent, tree_id=section.id,
parent=parent, tree_id=section.name,
)

@staticmethod
Expand Down Expand Up @@ -339,7 +340,7 @@ def _load_system_presets(self, all_presets: "dict[str, dict[str, list[PresetFile
dirname=preset_dir, preset_list=preset_list,
parent=presets_iter,
)
if self.ui_settings.preset_list_sections_expanded.get(Sections.PRESETS.id, True):
if self.ui_settings.preset_list_sections_expanded.get(Sections.PRESETS.name, True):
self.treeview.expand_row(self.treestore.get_path(presets_iter), False)

def _load_plugin_presets(self, all_presets: "dict[str, dict[str, list[PresetFile]]]") -> None:
Expand Down Expand Up @@ -388,7 +389,7 @@ def _load_plugin_presets(self, all_presets: "dict[str, dict[str, list[PresetFile
parent=plugin_presets_iter,
)

if self.ui_settings.preset_list_sections_expanded.get(Sections.PLUGINS.id, True):
if self.ui_settings.preset_list_sections_expanded.get(Sections.PLUGINS.name, True):
self.treeview.expand_row(self.treestore.get_path(plugins_iter), False)

def _load_user_presets(self, all_presets: "dict[str, dict[str, list[PresetFile]]]") -> None:
Expand All @@ -400,7 +401,7 @@ def _load_user_presets(self, all_presets: "dict[str, dict[str, list[PresetFile]]
dirname=preset_dir, preset_list=preset_list,
parent=user_presets_iter,
)
if self.ui_settings.preset_list_sections_expanded.get(Sections.USER.id, True):
if self.ui_settings.preset_list_sections_expanded.get(Sections.USER.name, True):
self.treeview.expand_row(self.treestore.get_path(user_presets_iter), False)

###########################################################################
Expand Down
11 changes: 6 additions & 5 deletions oomox_gui/theme_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,12 @@ def get_theme_options_by_key(
key: str,
fallback: "ThemeModelValue | None" = None,
) -> "list[ThemeModelValue]":
result = []
for _section_id, section in get_theme_model().items():
for theme_option in section:
if key == theme_option.get("key"):
result.append(theme_option)
result = [
theme_option
for section in get_theme_model().values()
for theme_option in section
if key == theme_option.get("key")
]
if not result and fallback:
return [fallback]
return result
Expand Down
2 changes: 1 addition & 1 deletion plugins/base16
Submodule base16 updated 1 files
+1 −1 oomox_plugin.py
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ select = [
"INT",
"LOG",
#"NPY", # numpy
#"PERF",
#"PYI",
"PERF",
"PYI",
"RSE",
"SLF",
#"SLOT",
Expand Down

0 comments on commit b639c33

Please sign in to comment.