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

@@ -1,4 +1,5 @@
# Python imports
from contextlib import suppress
import signal
import os
@@ -52,18 +53,15 @@ class Application:
except Exception:
ipc_server.send_test_ipc_message()
try:
with suppress(Exception):
ipc_server.create_ipc_listener()
except Exception as e:
...
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
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...

View File

@@ -46,7 +46,8 @@ class BaseControllerData:
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)
@@ -84,24 +85,22 @@ class BaseControllerData:
widget.remove(child)
def get_clipboard_data(self, encoding = "utf-8") -> str:
if which("xclip"):
command = ['xclip','-selection','clipboard']
else:
if not which("xclip"):
logger.info('xclip not found...')
return
command = ['xclip','-selection','clipboard']
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout = subprocess.PIPE)
retcode = proc.wait()
data = proc.stdout.read()
return data.decode(encoding).strip()
def set_clipboard_data(self, data: type, encoding = "utf-8") -> None:
if which("xclip"):
command = ['xclip','-selection','clipboard']
else:
if not which("xclip"):
logger.info('xclip not found...')
return
command = ['xclip','-selection','clipboard']
proc = subprocess.Popen(command, stdin = subprocess.PIPE)
proc.stdin.write(data.encode(encoding))
proc.stdin.close()

View File

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

View File

@@ -99,7 +99,7 @@ class VteWidget(Vte.Terminal):
try:
command_ran = lines[-1].split("-->:")[1].strip()
except VteWidgetException as e:
logger.debud(e)
logger.debug(e)
return
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_system.emit("handle_bridge_event", (event,))
def update_term_path(self, fpath):
def update_term_path(self, fpath: str):
self.dont_process = True
cmds = [f"cd '{fpath}'\n", "clear\n"]
for i in cmds:
self.run_command(i)
for cmd in cmds:
self.run_command(cmd)
def run_command(self, cmd):
def run_command(self, cmd: str):
self.feed_child_binary(bytes(cmd, 'utf8'))

View File

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