From 1aee234cbf9357864c6f733e0e869b8d8157cf47 Mon Sep 17 00:00:00 2001 From: Jamie Gravendeel Date: Mon, 5 Jan 2026 19:34:02 +0100 Subject: [PATCH] cartridges: Use generic methods in favor of TypeVar --- cartridges/ui/collection_details.py | 8 +++----- cartridges/ui/game_details.py | 8 +++----- cartridges/ui/window.py | 5 ++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/cartridges/ui/collection_details.py b/cartridges/ui/collection_details.py index 468da7c..8f338ac 100644 --- a/cartridges/ui/collection_details.py +++ b/cartridges/ui/collection_details.py @@ -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 diff --git a/cartridges/ui/game_details.py b/cartridges/ui/game_details.py index a1197b1..314ee2e 100644 --- a/cartridges/ui/game_details.py +++ b/cartridges/ui/game_details.py @@ -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() diff --git a/cartridges/ui/window.py b/cartridges/ui/window.py index 2c6971c..08c2515 100644 --- a/cartridges/ui/window.py +++ b/cartridges/ui/window.py @@ -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()