From 705153cc1956cd64b6f635f4f2a4d3040738d446 Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Thu, 23 Feb 2023 15:16:05 +0100
Subject: [PATCH] Add some argument checking

---
 b_asic/save_load_structure.py | 7 ++++++-
 b_asic/schedule.py            | 3 +++
 b_asic/simulation.py          | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/b_asic/save_load_structure.py b/b_asic/save_load_structure.py
index 57a2792e..1c8a70b5 100644
--- a/b_asic/save_load_structure.py
+++ b/b_asic/save_load_structure.py
@@ -33,6 +33,9 @@ def sfg_to_python(
         True if printing a schedule.
 
     """
+    if not isinstance(sfg, SFG):
+        raise TypeError("An SFG must be provided")
+
     _type = "Schedule" if schedule else "SFG"
 
     result = (
@@ -139,7 +142,7 @@ def sfg_to_python(
 
 def python_to_sfg(path: str) -> Tuple[SFG, Dict[str, Tuple[int, int]]]:
     """
-    Given a serialized file try to deserialize it and load it to the library.
+    Given a serialized file, try to deserialize it and load it to the library.
 
     Parameters
     ==========
@@ -167,6 +170,8 @@ def schedule_to_python(schedule: Schedule) -> str:
     schedule : Schedule
         The schedule to serialize.
     """
+    if not isinstance(schedule, Schedule):
+        raise TypeError("A Schedule must be provided")
     sfg_name = (
         schedule.sfg.name.replace(" ", "_").replace("-", "_")
         if schedule.sfg.name
diff --git a/b_asic/schedule.py b/b_asic/schedule.py
index 5bbfc2a6..cff3a166 100644
--- a/b_asic/schedule.py
+++ b/b_asic/schedule.py
@@ -83,6 +83,9 @@ class Schedule:
         laps: Optional[Dict[GraphID, int]] = None,
     ):
         """Construct a Schedule from an SFG."""
+        if not isinstance(sfg, SFG):
+            raise TypeError("An SFG must be provided")
+
         self._original_sfg = sfg()  # Make a copy
         self._sfg = sfg
         self._start_times = {}
diff --git a/b_asic/simulation.py b/b_asic/simulation.py
index 20716a42..bd4ae903 100644
--- a/b_asic/simulation.py
+++ b/b_asic/simulation.py
@@ -59,6 +59,9 @@ class Simulation:
         input_providers: Optional[Sequence[Optional[InputProvider]]] = None,
     ):
         """Construct a Simulation of an SFG."""
+        if not isinstance(sfg, SFG):
+            raise TypeError("An SFG must be provided")
+
         # Copy the SFG to make sure it's not modified from the outside.
         self._sfg = sfg()
         self._results = defaultdict(list)
-- 
GitLab