Skip to content
Snippets Groups Projects
Commit f50ee7ec authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Remove most pyright errors

Should be ok
parent 92731288
No related branches found
No related tags found
1 merge request!1First try of type hints
...@@ -43,18 +43,7 @@ DB_DEV_TYPE = "metadatadb.basic" ...@@ -43,18 +43,7 @@ DB_DEV_TYPE = "metadatadb.basic"
class Colors(enum.Enum): class Colors(enum.Enum):
DEFAULT = fore.WHITE DEFAULT = fore.WHITE
# ALIVE = fore.LIGHT_GRAY 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
ATTRIBUTS = fore.YELLOW ATTRIBUTS = fore.YELLOW
REQUEST = fore.RED REQUEST = fore.RED
IS_ALIVE = fore.MAGENTA IS_ALIVE = fore.MAGENTA
...@@ -148,7 +137,7 @@ class DeviceInfo(object): ...@@ -148,7 +137,7 @@ class DeviceInfo(object):
r.append([k, v]) r.append([k, v])
# attributes # attributes
if len(self.attributes) > 0: if self.attributes and len(self.attributes) > 0:
# tabulate has no minimal width so used this trick # tabulate has no minimal width so used this trick
r.append(['-'*22, '-'*46]) r.append(['-'*22, '-'*46])
r.append(['Attributes', '']) r.append(['Attributes', ''])
...@@ -172,9 +161,6 @@ class DeviceInfo(object): ...@@ -172,9 +161,6 @@ class DeviceInfo(object):
class ToolboxHelper(object): class ToolboxHelper(object):
def __init__(self) -> None: def __init__(self) -> None:
self.name = None # cmdline name self.name = None # cmdline name
self.parser = None
self.engine = None # toolbox engine
self.device = None # current device
self.devices = [] # devices list (alive / walker) self.devices = [] # devices list (alive / walker)
# idle detector / force exit # idle detector / force exit
self.exit_event = asyncio.Event() self.exit_event = asyncio.Event()
...@@ -311,7 +297,7 @@ class ToolboxHelper(object): ...@@ -311,7 +297,7 @@ class ToolboxHelper(object):
print(color_value, end='') print(color_value, end='')
msg.dump() msg.dump()
if color: if color:
print(style.RESET, end='') print(style.RESET, end='') # pyright: ignore
def color_for_msg(self, msg): def color_for_msg(self, msg):
color_value = Colors.DEFAULT color_value = Colors.DEFAULT
...@@ -420,8 +406,9 @@ class ToolboxHelper(object): ...@@ -420,8 +406,9 @@ class ToolboxHelper(object):
def run_until_timeout(self, timeout=3): def run_until_timeout(self, timeout=3):
""" run the engine until timeout """ """ run the engine until timeout """
self.engine.add_timer(self.quit, timeout) if self.engine:
self.engine.run() self.engine.add_timer(self.quit, timeout)
self.engine.run()
def run_until_idle(self): def run_until_idle(self):
self.engine.new_task(self.idle_detector()) self.engine.new_task(self.idle_detector())
...@@ -448,7 +435,7 @@ class ToolboxHelper(object): ...@@ -448,7 +435,7 @@ class ToolboxHelper(object):
def colorize(color, text): def colorize(color, text):
return f"{color}{text}{style.RESET}" return f"{color}{text}{style.RESET}" # pyright: ignore
def now(): def now():
...@@ -671,7 +658,7 @@ def log(): ...@@ -671,7 +658,7 @@ def log():
color_value = Colors.REPLY color_value = Colors.REPLY
if color: 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: else:
dump = f"{time.ctime()} {msg.source} {msg.dev_type}\t{msg.action} {msg.body}" dump = f"{time.ctime()} {msg.source} {msg.dev_type}\t{msg.action} {msg.body}"
print(dump) print(dump)
...@@ -979,7 +966,7 @@ def shell(): ...@@ -979,7 +966,7 @@ def shell():
print("$ pip install ipython\n") print("$ pip install ipython\n")
exit(1) 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 # "Event loop is closed" on the shell exit. To avoid issue
# we need to stop all tasks. # we need to stop all tasks.
async def on_stop(): async def on_stop():
...@@ -1012,4 +999,3 @@ def shell(): ...@@ -1012,4 +999,3 @@ def shell():
print("* Ending Engine") print("* Ending Engine")
eng.shutdown() eng.shutdown()
print("* Bye bye") print("* Bye bye")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment