From ea99fc5910f378662df17c04fe753dca7e0a4d78 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson <oscar.gustafsson@gmail.com> Date: Fri, 19 Apr 2024 15:19:18 +0200 Subject: [PATCH] Improve typing --- b_asic/GUI/drag_button.py | 6 ++++-- b_asic/resources.py | 4 ++-- b_asic/schedule.py | 4 ++-- b_asic/scheduler_gui/main_window.py | 14 +++++++++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/b_asic/GUI/drag_button.py b/b_asic/GUI/drag_button.py index cb6a9ca0..36d03c07 100644 --- a/b_asic/GUI/drag_button.py +++ b/b_asic/GUI/drag_button.py @@ -19,6 +19,8 @@ from b_asic.operation import Operation from b_asic.port import InputPort if TYPE_CHECKING: + from qtpy.QtWidgets import QGraphicsTextItem + from b_asic.GUI.main_window import SFGMainWindow @@ -90,13 +92,13 @@ class DragButton(QPushButton): """Return the type name of the underlying operation.""" return self.operation.type_name() - def add_label(self, label: str) -> None: + def add_label(self, label: "QGraphicsTextItem") -> None: """ Add label to button. Parameters ---------- - label : src + label : QGraphicsTextItem The label to add. """ self.label = label diff --git a/b_asic/resources.py b/b_asic/resources.py index 41dcac6b..1fad9dba 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -3,7 +3,7 @@ import re from collections import Counter, defaultdict from functools import reduce from math import log2 -from typing import Dict, Iterable, List, Optional, Tuple, TypeVar, Union +from typing import Dict, Iterable, List, Literal, Optional, Tuple, TypeVar, Union import matplotlib.pyplot as plt import networkx as nx @@ -864,7 +864,7 @@ class ProcessCollection: def split_on_execution_time( self, - heuristic: str = "left_edge", + heuristic: Literal["graph_color", "left_edge"] = "left_edge", coloring_strategy: str = "saturation_largest_first", ) -> List["ProcessCollection"]: """ diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 8365d194..54066e2e 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -7,7 +7,7 @@ Contains the schedule class for scheduling operations in an SFG. import io import sys from collections import defaultdict -from typing import Dict, List, Optional, Sequence, Tuple, cast +from typing import Dict, List, Literal, Optional, Sequence, Tuple, cast import matplotlib.pyplot as plt import numpy as np @@ -100,7 +100,7 @@ class Schedule: sfg: SFG, schedule_time: Optional[int] = None, cyclic: bool = False, - algorithm: str = "ASAP", + algorithm: Literal["ASAP", "ALAP", "provided"] = "ASAP", start_times: Optional[Dict[GraphID, int]] = None, laps: Optional[Dict[GraphID, int]] = None, max_resources: Optional[Dict[TypeName, int]] = None, diff --git a/b_asic/scheduler_gui/main_window.py b/b_asic/scheduler_gui/main_window.py index b331abcc..7a0c4114 100644 --- a/b_asic/scheduler_gui/main_window.py +++ b/b_asic/scheduler_gui/main_window.py @@ -14,7 +14,7 @@ import webbrowser from collections import defaultdict, deque from copy import deepcopy from importlib.machinery import SourceFileLoader -from typing import TYPE_CHECKING, Deque, List, Optional, cast +from typing import TYPE_CHECKING, Deque, List, Optional, cast, overload # Qt/qtpy import qtpy @@ -1006,6 +1006,18 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): self.actionToggle_full_screen.setIcon(get_icon('full-screen-exit')) +@overload +def start_scheduler(schedule: Schedule) -> Schedule: ... + + +@overload +def start_scheduler(schedule: None) -> Optional[Schedule]: ... + + +@overload +def start_scheduler() -> Optional[Schedule]: ... + + def start_scheduler(schedule: Optional[Schedule] = None) -> Optional[Schedule]: """ Start scheduler GUI. -- GitLab