From f50ee7ecd9fd46ef39e063aa38904afc3bb0e1fd Mon Sep 17 00:00:00 2001
From: jkerdreux-imt <jerome.kerdreux@imt-atlantique.fr>
Date: Wed, 27 Nov 2024 14:30:17 +0100
Subject: [PATCH] Remove most pyright errors

Should be ok
---
 apps/tools/xaal/tools/toolbox.py | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/apps/tools/xaal/tools/toolbox.py b/apps/tools/xaal/tools/toolbox.py
index 32938946..72a102e0 100644
--- a/apps/tools/xaal/tools/toolbox.py
+++ b/apps/tools/xaal/tools/toolbox.py
@@ -43,18 +43,7 @@ DB_DEV_TYPE = "metadatadb.basic"
 
 class Colors(enum.Enum):
     DEFAULT   = fore.WHITE
-    # ALIVE     = fore.LIGHT_GRAY
-    # ATTRIBUTS = fore.LIGHT_YELLOW
-    # REQUEST   = fore.LIGHT_RED
-    # IS_ALIVE  = fore.LIGHT_MAGENTA
-    # REPLY     = fore.LIGHT_CYAN
-    # NOTIFY    = fore.LIGHT_GREEN
-    # DEV_TYPE  = fore.LIGHT_BLUE
-    # ADDR      = fore.LIGHT_RED
-    # INFO      = fore.CYAN
-    # DB        = fore.SPRING_GREEN_1
-
-    ALIVE     = fore.LIGHT_GRAY
+    ALIVE     = fore.LIGHT_GRAY 
     ATTRIBUTS = fore.YELLOW
     REQUEST   = fore.RED
     IS_ALIVE  = fore.MAGENTA
@@ -148,7 +137,7 @@ class DeviceInfo(object):
             r.append([k, v])
 
         # attributes
-        if len(self.attributes) > 0:
+        if self.attributes and len(self.attributes) > 0:
             # tabulate has no minimal width so used this trick
             r.append(['-'*22, '-'*46])
             r.append(['Attributes', ''])
@@ -172,9 +161,6 @@ class DeviceInfo(object):
 class ToolboxHelper(object):
     def __init__(self) -> None:
         self.name = None       # cmdline name
-        self.parser = None
-        self.engine = None     # toolbox engine
-        self.device = None     # current device
         self.devices = []      # devices list (alive / walker)
         # idle detector / force exit
         self.exit_event = asyncio.Event()
@@ -311,7 +297,7 @@ class ToolboxHelper(object):
             print(color_value, end='')
         msg.dump()
         if color:
-            print(style.RESET, end='')
+            print(style.RESET, end='') # pyright: ignore
 
     def color_for_msg(self, msg):
         color_value = Colors.DEFAULT
@@ -420,8 +406,9 @@ class ToolboxHelper(object):
 
     def run_until_timeout(self, timeout=3):
         """ run the engine until timeout """
-        self.engine.add_timer(self.quit, timeout)
-        self.engine.run()
+        if self.engine:
+            self.engine.add_timer(self.quit, timeout)
+            self.engine.run()
 
     def run_until_idle(self):
         self.engine.new_task(self.idle_detector())
@@ -448,7 +435,7 @@ class ToolboxHelper(object):
 
 
 def colorize(color, text):
-    return f"{color}{text}{style.RESET}"
+    return f"{color}{text}{style.RESET}" # pyright: ignore
 
 
 def now():
@@ -671,7 +658,7 @@ def log():
             color_value = Colors.REPLY
 
         if color:
-            dump = f"{Colors.DEFAULT}{time.ctime()} {Colors.ADDR}{msg.source} {Colors.DEV_TYPE}{msg.dev_type}\t{color_value}{msg.action} {msg.body}{style.RESET}"
+            dump = f"{Colors.DEFAULT}{time.ctime()} {Colors.ADDR}{msg.source} {Colors.DEV_TYPE}{msg.dev_type}\t{color_value}{msg.action} {msg.body}{style.RESET}" # pyright: ignore
         else:
             dump = f"{time.ctime()} {msg.source} {msg.dev_type}\t{msg.action} {msg.body}"
         print(dump)
@@ -979,7 +966,7 @@ def shell():
         print("$ pip install ipython\n")
         exit(1)
 
-    # for a unknown reason, watchdog_task raise a RuntimeError: 
+    # for a unknown reason, watchdog_task raise a RuntimeError:
     # "Event loop is closed" on the shell exit. To avoid issue
     # we need to stop all tasks.
     async def on_stop():
@@ -1012,4 +999,3 @@ def shell():
     print("* Ending Engine")
     eng.shutdown()
     print("* Bye bye")
-
-- 
GitLab