Skip to content

Commit

Permalink
[QA] PEP and Type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
calendulish committed Jun 16, 2024
1 parent 9332ad7 commit b6922f4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/steam_tools_ng/gtk/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async def run_steamguard(self, play_event: asyncio.Event) -> None:

@while_window_realized
async def run_cardfarming(self, play_event: asyncio.Event) -> None:
assert isinstance(self.steamid, universe.SteamId)
cardfarming = core.cardfarming.main(self.steamid, play_event)

async for module_data in cardfarming:
Expand Down
4 changes: 2 additions & 2 deletions src/steam_tools_ng/gtk/coupon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import asyncio
import logging
import time
from typing import Any
from typing import Any, Tuple, List

from gi.repository import Gtk

Expand Down Expand Up @@ -164,7 +164,7 @@ async def send_trade_offer(self) -> None:
self.has_status = True
return

give = []
give: List[Tuple[int, ...]] = []
receive = []

if self.action == 'get':
Expand Down
3 changes: 1 addition & 2 deletions src/steam_tools_ng/gtk/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import asyncio
import binascii
import logging
from concurrent.futures import ProcessPoolExecutor
from typing import Any, Optional

import aiohttp
Expand Down Expand Up @@ -111,7 +110,7 @@ def __init__(

self.check_login_availability()
self.login_session = login.Login.get_session(0)
self.poll_task: Optional[asyncio.Task] = None
self.poll_task: Optional[asyncio.Task[Any]] = None
self.poll_cancelled = False

async def poll_login(self, steamid: int, client_id: str, request_id: str) -> None:
Expand Down
33 changes: 18 additions & 15 deletions src/steam_tools_ng/gtk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import functools
import html
import logging
import sys
import traceback
from collections import OrderedDict
from traceback import StackSummary
Expand Down Expand Up @@ -154,7 +155,7 @@ def clear(self, module: str) -> None:


class SimpleTextTreeItem(GObject.Object):
def __init__(self, *args: str, headers: Tuple[str], **kwargs) -> None:
def __init__(self, *args: str, headers: Tuple[str, ...], **kwargs: Any) -> None:
for name, value in kwargs.items():
setattr(self, name, value)

Expand All @@ -167,7 +168,7 @@ def __init__(self, *args: str, headers: Tuple[str], **kwargs) -> None:
log.debug(f'{name} param not set in {self}')

super(GObject.Object, self).__init__()
self.children = []
self.children: List[SimpleTextTreeItem] = []


class SimpleTextTree(Gtk.Grid):
Expand Down Expand Up @@ -261,14 +262,16 @@ def __init__(

self.attach(self._disabled_label, 0, 0, 1, 1)

def setup(self, view: Gtk.ListView, item: Gtk.ListItem, hide_expander: bool = True) -> None:
@staticmethod
def setup(view: Gtk.ListView, item: Gtk.ListItem, hide_expander: bool = True) -> None:
expander = Gtk.TreeExpander()
expander.set_hide_expander(hide_expander)
label = Gtk.Label()
expander.set_child(label)
item.set_child(expander)

def bind(self, view: Gtk.ListView, item: Gtk.ListItem, element: Optional[str] = None) -> None:
@staticmethod
def bind(view: Gtk.ListView, item: Gtk.ListItem, element: Optional[str] = None) -> None:
expander = item.get_child()
assert isinstance(expander, Gtk.TreeExpander)

Expand All @@ -290,7 +293,7 @@ def bind(self, view: Gtk.ListView, item: Gtk.ListItem, element: Optional[str] =
def item_factory(self, item: Gtk.ListItem) -> Optional[Gtk.TreeListModel]:
store = Gio.ListStore.new(SimpleTextTreeItem)

if type(item) == Gtk.TreeListRow:
if isinstance(item, Gtk.TreeListRow):
item = item.get_item()

if item.children:
Expand All @@ -301,7 +304,7 @@ def item_factory(self, item: Gtk.ListItem) -> Optional[Gtk.TreeListModel]:

return None

def new_item(self, *data: List[str], **kwargs) -> SimpleTextTreeItem:
def new_item(self, *data: str, **kwargs: Any) -> SimpleTextTreeItem:
return SimpleTextTreeItem(*data, headers=self.headers, **kwargs)

def append_row(self, row: Gtk.TreeListRow) -> None:
Expand Down Expand Up @@ -587,7 +590,7 @@ def __init__(self,
self.label = Gtk.Label()
self.label.set_name(name)
self.label.set_text(label)
#self.label.set_halign(Gtk.Align.START)
# self.label.set_halign(Gtk.Align.START)

self.attach(self.label, 0, 0, 1, 1)
self.attach_next_to(self.widget, self.label, Gtk.PositionType.RIGHT, 1, 1)
Expand All @@ -609,10 +612,10 @@ def __update_dropdown(self) -> None:
value = config.parser.get(self.section.get_name(), self.get_name())

try:
assert self.items is str, "received None from items"
current_option = list(self.items).index(value)
except ValueError:
import sys

assert self.items is str, "received None from items"
error_message = _("Please, fix your config file. Accepted values for {} are:\n{}").format(
self.name,
', '.join(self.items.keys()),
Expand Down Expand Up @@ -652,14 +655,14 @@ def set_visible(self, state: bool) -> None:
self.label.set_visible(state)
super(self.__class__, self).set_visible(state)

def connect(self, name: str, callback: Callable[..., Any], *args, **kwargs) -> None:
def connect(self, name: str, callback: Callable[..., Any], *args: Any, **kwargs: Any) -> None:
self.widget.connect(name, lambda widget, *data: callback(self, *data, *args, **kwargs))


class Section(Gtk.Grid):
def __init__(self, name: str) -> None:
super().__init__()
self.items = []
self.items: List[_SectionItem] = []

self.set_name(name)
self.set_row_spacing(10)
Expand Down Expand Up @@ -689,10 +692,10 @@ def stackup_section(self, text: str, stack: Gtk.Stack, *, scroll: bool = False)
name = self.get_name()

if scroll:
scroll = Gtk.ScrolledWindow()
scroll.set_overlay_scrolling(True)
scroll.set_child(self)
stack.add_titled(scroll, name, text)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_overlay_scrolling(True)
scrolled_window.set_child(self)
stack.add_titled(scrolled_window, name, text)
else:
stack.add_titled(self, name, text)

Expand Down
6 changes: 3 additions & 3 deletions src/steam_tools_ng/gtk/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ async def plugin_status(self) -> None:
status = getattr(self, f'{plugin_name}_status')

if not enabled:
def disabled_callback(status_) -> None:
def disabled_callback(status_: utils.SimpleStatus) -> None:
status_.set_status(_("Disabled"))
status_.set_info("")

Expand Down Expand Up @@ -773,13 +773,13 @@ def on_coupon_double_clicked(self, view: Gtk.ColumnView, position: int) -> None:
call([config.file_manager, url])

@staticmethod
def on_tree_selection_changed(view: Gtk.SingleSelection, position, item_count: int) -> None:
def on_tree_selection_changed(view: Gtk.SingleSelection, position: int, item_count: int) -> None:
item = view.get_selected_item()
if parent := item.get_parent():
view.set_selected(parent.get_position())

@staticmethod
def on_stack_child_changed(tabs: Gtk.Stack, *args) -> None:
def on_stack_child_changed(tabs: Gtk.Stack, *args: Any) -> None:
main_section = tabs.get_visible_child()

if not (config_stack := main_section.get_child_at(1, 1)):
Expand Down

0 comments on commit b6922f4

Please sign in to comment.