diff --git a/companion.py b/companion.py index f5641f01..44115248 100644 --- a/companion.py +++ b/companion.py @@ -182,7 +182,7 @@ def listify(thing: list | dict | None) -> list[Any]: JSON objects indexed by integers. Sparse arrays are converted to lists with gaps filled with None. """ - if thing is None: + if not thing: return [] if isinstance(thing, list): @@ -1295,13 +1295,10 @@ def index_possibly_sparse_list(data: Mapping[str, V] | list[V], key: int) -> V: >>> index_possibly_sparse_list(data, 0) 'test_list' """ - if isinstance(data, list): - return data[key] - - if isinstance(data, dict): - return data[str(key)] - - raise ValueError(f'Unexpected data type {type(data)}') + try: + return data[key] if isinstance(data, list) else data[str(key)] + except (KeyError, IndexError) as e: + raise ValueError(f'Unexpected data type or missing key: {type(data)}') from e ###################################################################### diff --git a/prefs.py b/prefs.py index 84f87569..7a3694b0 100644 --- a/prefs.py +++ b/prefs.py @@ -8,7 +8,6 @@ from pathlib import Path import subprocess import sys import tkinter as tk -from os import system from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812 from tkinter import ttk from itertools import count @@ -40,12 +39,14 @@ logger = get_main_logger() def open_folder(file: Path) -> None: """Open the given file in the OS file explorer.""" + # Ensure we are working with a resolved Path object + file_path = Path(file).resolve() if sys.platform.startswith('win'): # On Windows, use the "start" command to open the folder - system(f'start "" "{file}"') + subprocess.run(['start', '', file_path], shell=True) elif sys.platform.startswith('linux'): # On Linux, use the "xdg-open" command to open the folder - system(f'xdg-open "{file}"') + subprocess.run(['xdg-open', str(file_path)]) def help_open_system_profiler(parent) -> None: diff --git a/timeout_session.py b/timeout_session.py index 03d7de85..85514bbd 100644 --- a/timeout_session.py +++ b/timeout_session.py @@ -40,7 +40,11 @@ class TimeoutAdapter(HTTPAdapter): def new_session(timeout: int = REQUEST_TIMEOUT, session: Session | None = None) -> Session: - """DEPRECATED: Create a new requests.Session.""" + """ + Create a new requests.Session. + + DEPRECATED. Will be removed in a future version (6.3 or later). + """ warnings.warn( "timeout_session.new_session() is deprecated and will be removed. " "Use requests.Session() directly and pass explicit timeouts to request methods.",