Moved to use contextlib suppress pattern than empty exception blocks

This commit is contained in:
2025-10-21 22:20:06 -05:00
parent 7c0d87fd20
commit 60b55da973
6 changed files with 26 additions and 32 deletions

View File

@@ -77,4 +77,4 @@ def custom_except_hook(exc_type, exc_value, exc_traceback):
logger.error("Uncaught exception", exc_info = (exc_type, exc_value, exc_traceback)) logger.error("Uncaught exception", exc_info = (exc_type, exc_value, exc_traceback))
sys.excepthook = custom_except_hook sys.excepthook = custom_except_hook

View File

@@ -1,4 +1,5 @@
# Python imports # Python imports
from contextlib import suppress
import signal import signal
import os import os
@@ -52,18 +53,15 @@ class Application:
except Exception: except Exception:
ipc_server.send_test_ipc_message() ipc_server.send_test_ipc_message()
try: with suppress(Exception):
ipc_server.create_ipc_listener() ipc_server.create_ipc_listener()
except Exception as e:
...
def setup_debug_hook(self): def setup_debug_hook(self):
try: # Typically: ValueError: signal only works in main thread
with suppress(ValueError):
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows # kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
signal.signal( signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"), vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
debug_signal_handler debug_signal_handler
) )
except ValueError:
# Typically: ValueError: signal only works in main thread
...

View File

@@ -46,9 +46,10 @@ class BaseControllerData:
logger.info(f"Not a File: {arg}") logger.info(f"Not a File: {arg}")
if len(files) > 0: if len(files) == 0: return
settings_manager.set_is_starting_with_file(True)
settings_manager.set_starting_files(files) settings_manager.set_is_starting_with_file(True)
settings_manager.set_starting_files(files)
def get_base_container(self): def get_base_container(self):
return self.base_container return self.base_container
@@ -84,24 +85,22 @@ class BaseControllerData:
widget.remove(child) widget.remove(child)
def get_clipboard_data(self, encoding = "utf-8") -> str: def get_clipboard_data(self, encoding = "utf-8") -> str:
if which("xclip"): if not which("xclip"):
command = ['xclip','-selection','clipboard']
else:
logger.info('xclip not found...') logger.info('xclip not found...')
return return
command = ['xclip','-selection','clipboard']
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout = subprocess.PIPE) proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout = subprocess.PIPE)
retcode = proc.wait() retcode = proc.wait()
data = proc.stdout.read() data = proc.stdout.read()
return data.decode(encoding).strip() return data.decode(encoding).strip()
def set_clipboard_data(self, data: type, encoding = "utf-8") -> None: def set_clipboard_data(self, data: type, encoding = "utf-8") -> None:
if which("xclip"): if not which("xclip"):
command = ['xclip','-selection','clipboard']
else:
logger.info('xclip not found...') logger.info('xclip not found...')
return return
command = ['xclip','-selection','clipboard']
proc = subprocess.Popen(command, stdin = subprocess.PIPE) proc = subprocess.Popen(command, stdin = subprocess.PIPE)
proc.stdin.write(data.encode(encoding)) proc.stdin.write(data.encode(encoding))
proc.stdin.close() proc.stdin.close()

View File

@@ -1,4 +1,5 @@
# Python imports # Python imports
from contextlib import suppress
import os import os
# Lib imports # Lib imports
@@ -58,11 +59,9 @@ class OpenFilesButton(Gtk.Button):
chooser.set_select_multiple(True) chooser.set_select_multiple(True)
try: with suppress(Exception):
folder = widget.get_current_file().get_parent() if not start_dir else start_dir folder = widget.get_current_file().get_parent() if not start_dir else start_dir
chooser.set_current_folder( folder.get_path() ) chooser.set_current_folder( folder.get_path() )
except Exception as e:
...
response = chooser.run() response = chooser.run()
if not response == Gtk.ResponseType.OK: if not response == Gtk.ResponseType.OK:

View File

@@ -99,7 +99,7 @@ class VteWidget(Vte.Terminal):
try: try:
command_ran = lines[-1].split("-->:")[1].strip() command_ran = lines[-1].split("-->:")[1].strip()
except VteWidgetException as e: except VteWidgetException as e:
logger.debud(e) logger.debug(e)
return return
if not command_ran[0:3].encode() in self.cd_cmd_prefix: if not command_ran[0:3].encode() in self.cd_cmd_prefix:
@@ -114,12 +114,12 @@ class VteWidget(Vte.Terminal):
event = Event("pty_path_updated", "", target_path) event = Event("pty_path_updated", "", target_path)
event_system.emit("handle_bridge_event", (event,)) event_system.emit("handle_bridge_event", (event,))
def update_term_path(self, fpath): def update_term_path(self, fpath: str):
self.dont_process = True self.dont_process = True
cmds = [f"cd '{fpath}'\n", "clear\n"] cmds = [f"cd '{fpath}'\n", "clear\n"]
for i in cmds: for cmd in cmds:
self.run_command(i) self.run_command(cmd)
def run_command(self, cmd): def run_command(self, cmd: str):
self.feed_child_binary(bytes(cmd, 'utf8')) self.feed_child_binary(bytes(cmd, 'utf8'))

View File

@@ -12,13 +12,11 @@ class SingletonError(Exception):
class Singleton: class Singleton:
ccount = 0 _instance = None
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
obj = super(Singleton, cls).__new__(cls) if cls._instance:
cls.ccount += 1 raise SingletonError(f"'{cls.__name__}' is a Singleton. Cannot create a new instance...")
if cls.ccount == 2: cls._instance = super(Singleton, cls).__new__(cls)
raise SingletonError(f"Exceeded {cls.__name__} instantiation limit...") return cls._instance
return obj