cartridges: Prefer cast over isinstance
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from gi.repository import Adw, Gdk, Gio, GObject, Gtk
|
from gi.repository import Adw, Gdk, Gio, GObject, Gtk
|
||||||
@@ -81,11 +81,7 @@ class GameDetails(Adw.NavigationPage):
|
|||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def _downscale_image(self, _obj, cover: Gdk.Texture | None) -> Gdk.Texture | None:
|
def _downscale_image(self, _obj, cover: Gdk.Texture | None) -> Gdk.Texture | None:
|
||||||
if (
|
if cover and (renderer := cast(Gtk.Native, self.props.root).get_renderer()):
|
||||||
cover
|
|
||||||
and isinstance(root := self.props.root, Gtk.Native)
|
|
||||||
and (renderer := root.get_renderer())
|
|
||||||
):
|
|
||||||
cover.snapshot(snapshot := Gtk.Snapshot.new(), 3, 3)
|
cover.snapshot(snapshot := Gtk.Snapshot.new(), 3, 3)
|
||||||
if node := snapshot.to_node():
|
if node := snapshot.to_node():
|
||||||
return renderer.render_texture(node)
|
return renderer.render_texture(node)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import locale
|
import locale
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from typing import Any, TypeVar
|
from typing import Any, TypeVar, cast
|
||||||
|
|
||||||
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
||||||
|
|
||||||
@@ -81,9 +81,8 @@ class Window(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def _show_details(self, grid: Gtk.GridView, position: int):
|
def _show_details(self, grid: Gtk.GridView, position: int):
|
||||||
if isinstance(model := grid.props.model, Gio.ListModel):
|
self.details.game = cast(Gio.ListModel, grid.props.model).get_item(position)
|
||||||
self.details.game = model.get_item(position)
|
self.navigation_view.push_by_tag("details")
|
||||||
self.navigation_view.push_by_tag("details")
|
|
||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def _search_started(self, entry: Gtk.SearchEntry):
|
def _search_started(self, entry: Gtk.SearchEntry):
|
||||||
@@ -137,11 +136,7 @@ class Window(Adw.ApplicationWindow):
|
|||||||
self.sorter.changed(Gtk.SorterChange.DIFFERENT)
|
self.sorter.changed(Gtk.SorterChange.DIFFERENT)
|
||||||
|
|
||||||
def _edit(self, pos: int):
|
def _edit(self, pos: int):
|
||||||
if isinstance(self.grid.props.model, Gio.ListModel) and (
|
self.details.game = cast(Gio.ListModel, self.grid.props.model).get_item(pos)
|
||||||
game := self.grid.props.model.get_item(pos)
|
|
||||||
):
|
|
||||||
self.details.game = game
|
|
||||||
|
|
||||||
self.navigation_view.push_by_tag("details")
|
self.navigation_view.push_by_tag("details")
|
||||||
self.details.edit()
|
self.details.edit()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user