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