make type checking more strict
This commit is contained in:
parent
65cdd51af2
commit
780ffb9c8f
|
@ -19,8 +19,8 @@ test_driver = ["py.typed"]
|
|||
target-version = "py311"
|
||||
line-length = 88
|
||||
|
||||
select = ["E", "F", "I", "U", "N", "RUF"]
|
||||
ignore = ["E501"]
|
||||
select = ["E", "F", "I", "U", "N", "RUF", "ANN"]
|
||||
ignore = ["E501", "ANN101", "ANN401"]
|
||||
|
||||
[tool.mypy]
|
||||
python_version = "3.11"
|
||||
|
|
|
@ -36,7 +36,7 @@ def retry(fn: Callable, timeout: int = 900) -> None:
|
|||
|
||||
|
||||
class Machine:
|
||||
def __init__(self, name: str, toplevel: Path, rootdir: Path, out_dir: str):
|
||||
def __init__(self, name: str, toplevel: Path, rootdir: Path, out_dir: str) -> None:
|
||||
self.name = name
|
||||
self.toplevel = toplevel
|
||||
self.out_dir = out_dir
|
||||
|
@ -198,7 +198,7 @@ class Machine:
|
|||
timing out.
|
||||
"""
|
||||
|
||||
def check_active(_: Any) -> bool:
|
||||
def check_active(_: bool) -> bool:
|
||||
info = self.get_unit_info(unit)
|
||||
state = info["ActiveState"]
|
||||
if state == "failed":
|
||||
|
@ -247,7 +247,7 @@ def setup_filesystems() -> None:
|
|||
|
||||
|
||||
class Driver:
|
||||
def __init__(self, containers: list[Path], testscript: str, out_dir: str):
|
||||
def __init__(self, containers: list[Path], testscript: str, out_dir: str) -> None:
|
||||
self.containers = containers
|
||||
self.testscript = testscript
|
||||
self.out_dir = out_dir
|
||||
|
|
|
@ -7,11 +7,12 @@ import socket
|
|||
import subprocess
|
||||
import time
|
||||
import urllib.request
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Any, Iterator, Optional
|
||||
from typing import Any
|
||||
|
||||
|
||||
class ClanError(Exception):
|
||||
|
@ -37,7 +38,7 @@ def try_connect_port(port: int) -> bool:
|
|||
return result == 0
|
||||
|
||||
|
||||
def find_free_port() -> Optional[int]:
|
||||
def find_free_port() -> int | None:
|
||||
"""Find an unused localhost port from 1024-65535 and return it."""
|
||||
with contextlib.closing(socket.socket(type=socket.SOCK_STREAM)) as sock:
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
|
@ -69,7 +70,7 @@ class ZerotierController:
|
|||
path: str,
|
||||
method: str = "GET",
|
||||
headers: dict[str, str] = {},
|
||||
data: Optional[dict[str, Any]] = None,
|
||||
data: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
body = None
|
||||
headers = headers.copy()
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -9,6 +9,6 @@ exclude = "clan_cli.nixpkgs"
|
|||
|
||||
[tool.ruff]
|
||||
line-length = 88
|
||||
|
||||
select = [ "E", "F", "I", "U", "N"]
|
||||
ignore = [ "E501" ]
|
||||
target-version = "py311"
|
||||
select = [ "E", "F", "I", "U", "N", "RUF", "ANN" ]
|
||||
ignore = [ "E501", "ANN101", "ANN401"]
|
||||
|
|
Loading…
Reference in New Issue
Block a user