From 540c84d97a6ebcf37d5f7fb6bdf86bee2a6bc29c Mon Sep 17 00:00:00 2001
From: Simon Bjurek <simbj106@student.liu.se>
Date: Tue, 8 Apr 2025 14:10:32 +0200
Subject: [PATCH] Add flake8-builtins ruff rule

---
 b_asic/resources.py                        |  8 ++++----
 b_asic/scheduler_gui/preferences_dialog.py | 14 +++++++-------
 b_asic/signal_flow_graph.py                | 18 ++++++++++--------
 pyproject.toml                             |  6 +++---
 4 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/b_asic/resources.py b/b_asic/resources.py
index d8d2615d..1b5f93fb 100644
--- a/b_asic/resources.py
+++ b/b_asic/resources.py
@@ -116,8 +116,8 @@ def _get_destination(
     name = var.name.split(".")[0]
     for pe in pes:
         for process in pe.processes:
-            for input in process.operation.inputs:
-                input_op = input.connected_source.operation
+            for input_port in process.operation.inputs:
+                input_op = input_port.connected_source.operation
                 if input_op.graph_id == name:
                     return pe
     raise ValueError("Destination could not be found for the given variable.")
@@ -1336,8 +1336,8 @@ class ProcessCollection:
         count = 0
         for pe in processing_elements:
             for process in pe.processes:
-                for input in process.operation.inputs:
-                    input_op = input.connected_source.operation
+                for input_port in process.operation.inputs:
+                    input_op = input_port.connected_source.operation
                     if input_op.graph_id in collection_process_names:
                         count += 1
                         break
diff --git a/b_asic/scheduler_gui/preferences_dialog.py b/b_asic/scheduler_gui/preferences_dialog.py
index 6ca990ca..45d4eff9 100644
--- a/b_asic/scheduler_gui/preferences_dialog.py
+++ b/b_asic/scheduler_gui/preferences_dialog.py
@@ -227,11 +227,11 @@ class PreferencesDialog(QWidget):
         button.setText(color.name)
         if color.name == "Latency color":
             button.pressed.connect(
-                lambda: self.set_latency_color_by_type_name(all=True)
+                lambda: self.set_latency_color_by_type_name(modify_all=True)
             )
         elif color.name == "Latency color per type":
             button.pressed.connect(
-                lambda: self.set_latency_color_by_type_name(all=False)
+                lambda: self.set_latency_color_by_type_name(modify_all=False)
             )
         else:
             button.pressed.connect(lambda: self.color_button_clicked(color))
@@ -262,13 +262,13 @@ class PreferencesDialog(QWidget):
             self._bold_button.set_color(QColor("snow"))
         self.update_font()
 
-    def set_latency_color_by_type_name(self, all: bool) -> None:
+    def set_latency_color_by_type_name(self, modify_all: bool) -> None:
         """
         Set latency color based on operation type names.
 
         Parameters
         ----------
-        all : bool
+        modify_all : bool
             Indicates if the color of all type names to be modified.
         """
         if LATENCY_COLOR_TYPE.changed:
@@ -277,7 +277,7 @@ class PreferencesDialog(QWidget):
             current_color = LATENCY_COLOR_TYPE.DEFAULT
 
         # Prompt user to select operation type if not setting color for all types
-        if not all:
+        if not modify_all:
             used_types = self._parent._schedule.get_used_type_names()
             operation_type, ok = QInputDialog.getItem(
                 self, "Select operation type", "Type", used_types, editable=False
@@ -287,14 +287,14 @@ class PreferencesDialog(QWidget):
             ok = False
 
         # Open a color dialog to get the selected color
-        if all or ok:
+        if modify_all or ok:
             color = QColorDialog.getColor(
                 current_color, self, f"Select the color of {operation_type}"
             )
 
             # If a valid color is selected, update color settings and graph
             if color.isValid():
-                if all:
+                if modify_all:
                     LATENCY_COLOR_TYPE.changed = True
                     self._parent._color_changed_per_type = False
                     self._parent._changed_operation_colors.clear()
diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py
index 9b95fed5..4b7867f6 100644
--- a/b_asic/signal_flow_graph.py
+++ b/b_asic/signal_flow_graph.py
@@ -1327,7 +1327,7 @@ class SFG(AbstractOperation):
         self, original_component: GraphComponent
     ) -> GraphComponent:
         if original_component in self._original_components_to_new:
-            id = (
+            graph_id = (
                 original_component.name
                 if original_component.name
                 else (
@@ -1336,7 +1336,7 @@ class SFG(AbstractOperation):
                     else original_component.type_name()
                 )
             )
-            raise ValueError(f"Tried to add duplicate SFG component: {id}")
+            raise ValueError(f"Tried to add duplicate SFG component: {graph_id}")
         new_component = original_component.copy()
         self._original_components_to_new[original_component] = new_component
         if not new_component.graph_id or new_component.graph_id in self._used_ids:
@@ -1367,7 +1367,7 @@ class SFG(AbstractOperation):
             # Connect input ports to new signals.
             for original_input_port in original_op.inputs:
                 if original_input_port.signal_count < 1:
-                    id = (
+                    graph_id = (
                         original_op.name
                         if original_op.name
                         else (
@@ -1376,7 +1376,9 @@ class SFG(AbstractOperation):
                             else original_op.type_name()
                         )
                     )
-                    raise ValueError(f"Unconnected input port in SFG. Operation: {id}")
+                    raise ValueError(
+                        f"Unconnected input port in SFG. Operation: {graph_id}"
+                    )
 
                 for original_signal in original_input_port.signals:
                     # Check if the signal is one of the SFG's input signals.
@@ -1879,8 +1881,8 @@ class SFG(AbstractOperation):
                 inputs_used.append(int(used_input))
         if inputs_used == []:
             return []
-        for input in inputs_used:
-            input_op = self._input_operations[input]
+        for input_index in inputs_used:
+            input_op = self._input_operations[input_index]
         queue: deque[Operation] = deque([input_op])
         visited: set[Operation] = {input_op}
         dict_of_sfg = {}
@@ -1965,8 +1967,8 @@ class SFG(AbstractOperation):
                                 visited.add(new_op)
                         else:
                             raise ValueError("Source does not exist")
-        for input in input_index_used:
-            input_op = self._input_operations[input]
+        for input_index in input_index_used:
+            input_op = self._input_operations[input_index]
             queue: deque[Operation] = deque([input_op])
             visited: set[Operation] = {input_op}
             while queue:
diff --git a/pyproject.toml b/pyproject.toml
index 7e589e00..f2d09feb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -98,11 +98,11 @@ ignore_missing_imports = true
 precision = 2
 
 [tool.ruff]
-exclude = ["examples"]
+exclude = ["examples", "test", "docs_sphinx"]
 
 [tool.ruff.lint]
-select = ["E4", "E7", "E9", "F", "SIM", "B", "NPY", "C4", "UP", "RUF"]
-ignore = ["F403", "B008", "B021", "B006", "UP038", "RUF023"]
+select = ["E4", "E7", "E9", "F", "SIM", "B", "NPY", "C4", "UP", "RUF", "A"]
+ignore = ["F403", "B008", "B021", "B006", "UP038", "RUF023", "A005"]
 
 [tool.typos]
 default.extend-identifiers = { ba = "ba", addd0 = "addd0", inout = "inout", ArChItEctUrE = "ArChItEctUrE" }
-- 
GitLab