cartridges: Use generic methods in favor of TypeVar

This commit is contained in:
Jamie Gravendeel
2026-01-05 19:34:02 +01:00
parent 21588fe92b
commit 1aee234cbf
3 changed files with 8 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
from itertools import product
from typing import Any, NamedTuple, TypeVar, cast
from typing import Any, NamedTuple, cast
from gi.repository import Adw, Gio, GObject, Gtk
@@ -40,8 +40,6 @@ _ICONS = (
_Icon("fist", ""),
)
_T = TypeVar("_T")
@Gtk.Template.from_resource(f"{PREFIX}/collection-details.ui")
class CollectionDetails(Adw.Dialog):
@@ -132,9 +130,9 @@ class CollectionDetails(Adw.Dialog):
self.close()
@Gtk.Template.Callback()
def _or(self, _obj, first: _T, second: _T) -> _T:
def _or[T](self, _obj, first: T, second: T) -> T:
return first or second
@Gtk.Template.Callback()
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
def _if_else[T](self, _obj, condition: object, first: T, second: T) -> T:
return first if condition else second

View File

@@ -7,7 +7,7 @@ import sys
import time
from datetime import UTC, datetime
from gettext import gettext as _
from typing import Any, TypeVar, cast
from typing import Any, cast
from urllib.parse import quote
from gi.repository import Adw, Gdk, Gio, GLib, GObject, Gtk
@@ -26,8 +26,6 @@ _REQUIRED_PROPERTIES = {
prop.name for prop in games.PROPERTIES if prop.editable and prop.required
}
_T = TypeVar("_T")
@Gtk.Template.from_resource(f"{PREFIX}/game-details.ui")
class GameDetails(Adw.NavigationPage):
@@ -148,11 +146,11 @@ class GameDetails(Adw.NavigationPage):
self.collections_box.finish()
@Gtk.Template.Callback()
def _or(self, _obj, first: _T, second: _T) -> _T:
def _or[T](self, _obj, first: T, second: T) -> T:
return first or second
@Gtk.Template.Callback()
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
def _if_else[T](self, _obj, condition: object, first: T, second: T) -> T:
return first if condition else second
@Gtk.Template.Callback()

View File

@@ -6,7 +6,7 @@
import sys
from collections.abc import Callable
from gettext import gettext as _
from typing import Any, TypeVar, cast
from typing import Any, cast
from gi.repository import Adw, Gio, GLib, GObject, Gtk
@@ -34,7 +34,6 @@ SORT_MODES = {
"oldest": ("added", True),
}
_T = TypeVar("_T")
type _UndoFunc = Callable[[], Any]
@@ -214,7 +213,7 @@ class Window(Adw.ApplicationWindow):
gamepads.setup_monitor() # pyright: ignore[reportPossiblyUnboundVariable]
@Gtk.Template.Callback()
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
def _if_else[T](self, _obj, condition: object, first: T, second: T) -> T:
return first if condition else second
@Gtk.Template.Callback()