make type checking more strict
This commit is contained in:
@@ -8,7 +8,7 @@ class ClanHttpError(ClanError):
|
||||
status_code: int
|
||||
msg: str
|
||||
|
||||
def __init__(self, status_code: int, msg: str):
|
||||
def __init__(self, status_code: int, msg: str) -> None:
|
||||
self.status_code = status_code
|
||||
self.msg = msg
|
||||
super().__init__(msg)
|
||||
|
||||
@@ -55,5 +55,5 @@ ignore_missing_imports = true
|
||||
[tool.ruff]
|
||||
target-version = "py311"
|
||||
line-length = 88
|
||||
select = ["E", "F", "I", "U", "N", "RUF"]
|
||||
ignore = ["E501", "E402"]
|
||||
select = ["E", "F", "I", "U", "N", "RUF", "ANN"]
|
||||
ignore = ["E501", "E402", "ANN101", "ANN401"]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import gi
|
||||
|
||||
@@ -14,7 +15,7 @@ from .ui.clan_select_list import ClanSelectPage
|
||||
|
||||
|
||||
class VM:
|
||||
def __init__(self, url: str, autostart: bool, path: Path):
|
||||
def __init__(self, url: str, autostart: bool, path: Path) -> None:
|
||||
self.url = url
|
||||
self.autostart = autostart
|
||||
self.path = path
|
||||
@@ -32,7 +33,7 @@ vms.extend(vms)
|
||||
|
||||
|
||||
class ClanJoinPage(Gtk.Box):
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.page = Gtk.Box()
|
||||
self.set_border_width(10)
|
||||
@@ -60,22 +61,22 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
# Must be called AFTER all components were added
|
||||
self.show_all()
|
||||
|
||||
def on_quit(self, *args):
|
||||
def on_quit(self, *args: Any) -> None:
|
||||
Gio.Application.quit(self.get_application())
|
||||
|
||||
|
||||
class Application(Gtk.Application):
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
application_id=constants["APPID"], flags=Gio.ApplicationFlags.FLAGS_NONE
|
||||
)
|
||||
self.init_style()
|
||||
|
||||
def do_startup(self):
|
||||
def do_startup(self) -> None:
|
||||
Gtk.Application.do_startup(self)
|
||||
Gtk.init(sys.argv)
|
||||
|
||||
def do_activate(self):
|
||||
def do_activate(self) -> None:
|
||||
win = self.props.active_window
|
||||
if not win:
|
||||
# win = SwitchTreeView(application=self)
|
||||
@@ -83,7 +84,7 @@ class Application(Gtk.Application):
|
||||
win.present()
|
||||
|
||||
# TODO: For css styling
|
||||
def init_style(self):
|
||||
def init_style(self) -> None:
|
||||
pass
|
||||
# css_provider = Gtk.CssProvider()
|
||||
# css_provider.load_from_resource(constants['RESOURCEID'] + '/style.css')
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
from collections.abc import Callable
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..app import VM
|
||||
|
||||
|
||||
class ClanSelectPage(Gtk.Box):
|
||||
def __init__(self, vms):
|
||||
def __init__(self, vms: list["VM"]) -> None:
|
||||
super().__init__(orientation=Gtk.Orientation.VERTICAL, expand=True)
|
||||
|
||||
self.add(ClanSelectList(vms, self.on_cell_toggled, self.on_select_row))
|
||||
@@ -12,16 +18,16 @@ class ClanSelectPage(Gtk.Box):
|
||||
)
|
||||
)
|
||||
|
||||
def on_start_clicked(self, widget):
|
||||
def on_start_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Start clicked")
|
||||
|
||||
def on_stop_clicked(self, widget):
|
||||
def on_stop_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Stop clicked")
|
||||
|
||||
def on_backup_clicked(self, widget):
|
||||
def on_backup_clicked(self, widget: Gtk.Widget) -> None:
|
||||
print("Backup clicked")
|
||||
|
||||
def on_cell_toggled(self, widget, path):
|
||||
def on_cell_toggled(self, widget: Gtk.Widget, path: str) -> None:
|
||||
print(f"on_cell_toggled: {path}")
|
||||
# Get the current value from the model
|
||||
current_value = self.list_store[path][1]
|
||||
@@ -32,14 +38,19 @@ class ClanSelectPage(Gtk.Box):
|
||||
# Print the updated value
|
||||
print("Switched", path, "to", self.list_store[path][1])
|
||||
|
||||
def on_select_row(self, selection):
|
||||
def on_select_row(self, selection: Gtk.TreeSelection) -> None:
|
||||
model, row = selection.get_selected()
|
||||
if row is not None:
|
||||
print(f"Selected {model[row][0]}")
|
||||
|
||||
|
||||
class ClanSelectButtons(Gtk.Box):
|
||||
def __init__(self, on_start_clicked, on_stop_clicked, on_backup_clicked):
|
||||
def __init__(
|
||||
self,
|
||||
on_start_clicked: Callable[[Gtk.Widget], None],
|
||||
on_stop_clicked: Callable[[Gtk.Widget], None],
|
||||
on_backup_clicked: Callable[[Gtk.Widget], None],
|
||||
) -> None:
|
||||
super().__init__(
|
||||
orientation=Gtk.Orientation.HORIZONTAL, margin_bottom=10, margin_top=10
|
||||
)
|
||||
@@ -56,7 +67,12 @@ class ClanSelectButtons(Gtk.Box):
|
||||
|
||||
|
||||
class ClanSelectList(Gtk.Box):
|
||||
def __init__(self, vms, on_cell_toggled, on_select_row):
|
||||
def __init__(
|
||||
self,
|
||||
vms: list["VM"],
|
||||
on_cell_toggled: Callable[[Gtk.Widget, str], None],
|
||||
on_select_row: Callable[[Gtk.TreeSelection], None],
|
||||
) -> None:
|
||||
super().__init__(expand=True)
|
||||
self.vms = vms
|
||||
|
||||
|
||||
@@ -24,5 +24,5 @@ ignore_missing_imports = true
|
||||
[tool.ruff]
|
||||
target-version = "py311"
|
||||
line-length = 88
|
||||
select = ["E", "F", "I", "N", "RUF", "U"]
|
||||
ignore = ["E501", "E402", "N802"]
|
||||
select = [ "E", "F", "I", "U", "N", "RUF", "ANN" ]
|
||||
ignore = ["E501", "E402", "N802", "ANN101", "ANN401"]
|
||||
|
||||
Reference in New Issue
Block a user