From 36811b2de3e8dd16b67f7533efe35bcaf02c270b Mon Sep 17 00:00:00 2001 From: Travis Vasceannie Date: Sun, 18 Jan 2026 07:07:38 +0000 Subject: [PATCH] refactor: apply named expressions, conditional expressions, and destructuring for improved conciseness and readability. --- client/src/api/tauri-adapter.ts | 2 +- client/src/hooks/use-audio-devices.ts | 14 +++++++------- client/src/lib/client-log-events.ts | 2 +- .../application/services/asr_config/service.py | 2 +- src/noteflow/infrastructure/logging/config.py | 11 +++++------ src/noteflow/infrastructure/logging/processors.py | 4 +--- .../persistence/_migrations/_alembic_commands.py | 12 ++++++++---- .../persistence/repositories/entity_repo.py | 3 +-- src/noteflow/infrastructure/platform/__init__.py | 10 ++-------- 9 files changed, 27 insertions(+), 33 deletions(-) diff --git a/client/src/api/tauri-adapter.ts b/client/src/api/tauri-adapter.ts index d8f845a..aa77af8 100644 --- a/client/src/api/tauri-adapter.ts +++ b/client/src/api/tauri-adapter.ts @@ -22,7 +22,7 @@ import { errorLog } from '@/lib/debug'; import { StreamingQueue } from '@/lib/async-utils'; const logError = errorLog('TauriTranscriptionStream'); -const DEFAULT_PROJECT_ID = IdentityDefaults.DEFAULT_PROJECT_ID; +const {DEFAULT_PROJECT_ID} = IdentityDefaults; function normalizeProjectId(projectId?: string): string | undefined { const trimmed = projectId?.trim(); diff --git a/client/src/hooks/use-audio-devices.ts b/client/src/hooks/use-audio-devices.ts index 90c9b2a..2efc066 100644 --- a/client/src/hooks/use-audio-devices.ts +++ b/client/src/hooks/use-audio-devices.ts @@ -22,7 +22,7 @@ addClientLog({ level: 'debug', source: 'app', message: 'use-audio-devices.ts MODULE LOADED', - metadata: { isTauri: isTauriEnvironment() }, + metadata: { isTauri: String(isTauriEnvironment()) }, }); const log = debug('useAudioDevices'); @@ -48,7 +48,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD useEffect(() => { let mounted = true; - async function hydrateFromPreferences(): Promise { + const hydrateFromPreferences = async (): Promise => { await waitForHydration(); if (!mounted) { return; @@ -70,7 +70,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD setMicGain(prefs.audio_devices.mic_gain ?? 1.0); setSystemGain(prefs.audio_devices.system_gain ?? 1.0); setIsHydratedState(true); - } + }; void hydrateFromPreferences(); @@ -138,7 +138,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD level: 'debug', source: 'app', message: 'loadDevices: ENTRY', - metadata: { isTauri: isTauriEnvironment() }, + metadata: { isTauri: String(isTauriEnvironment()) }, }); try { @@ -260,7 +260,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD level: 'debug', source: 'app', message: 'Skipping output auto-select (user should choose manually)', - metadata: { available_count: outputs.length }, + metadata: { available_count: String(outputs.length) }, }); } return; @@ -324,7 +324,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD level: 'info', source: 'app', message: 'Audio device selected', - metadata: { device_type: 'input', device_id: deviceId, device_name: deviceLabel }, + metadata: { device_type: 'input', device_id: deviceId, device_name: deviceLabel ?? '' }, }); if (isTauriEnvironment()) { try { @@ -356,7 +356,7 @@ export function useAudioDevices(options: UseAudioDevicesOptions = {}): UseAudioD level: 'info', source: 'app', message: 'Audio device selected', - metadata: { device_type: 'output', device_id: deviceId, device_name: deviceLabel }, + metadata: { device_type: 'output', device_id: deviceId, device_name: deviceLabel ?? '' }, }); if (isTauriEnvironment()) { try { diff --git a/client/src/lib/client-log-events.ts b/client/src/lib/client-log-events.ts index ff84e6a..c9d7c85 100644 --- a/client/src/lib/client-log-events.ts +++ b/client/src/lib/client-log-events.ts @@ -169,7 +169,7 @@ export const clientLog = { }, // Audio Devices - deviceSelectionFailed(deviceType: 'input' | 'output', deviceId: string, error?: string): void { + deviceSelectionFailed(deviceType: 'input' | 'output' | 'system', deviceId: string, error?: string): void { emit('error', 'app', 'Device selection failed', { device_type: deviceType, device_id: deviceId, diff --git a/src/noteflow/application/services/asr_config/service.py b/src/noteflow/application/services/asr_config/service.py index 528b6f7..23a4037 100644 --- a/src/noteflow/application/services/asr_config/service.py +++ b/src/noteflow/application/services/asr_config/service.py @@ -92,7 +92,7 @@ class AsrConfigService: """Check preconditions for ASR reconfiguration.""" if has_active_recordings: return "Cannot reconfigure ASR while recordings are active" - return "ASR engine is not available" if not self._engine_manager.engine_available else None + return None if self._engine_manager.engine_available else "ASR engine is not available" async def start_reconfiguration( self, diff --git a/src/noteflow/infrastructure/logging/config.py b/src/noteflow/infrastructure/logging/config.py index decd5c3..aac294d 100644 --- a/src/noteflow/infrastructure/logging/config.py +++ b/src/noteflow/infrastructure/logging/config.py @@ -123,12 +123,11 @@ def _render_for_rich_handler( """ event = str(event_dict.get("event", "")) - # Include select user context keys if present - context_parts = [ - f"{key}={event_dict[key]}" for key in _RICH_CONTEXT_KEYS if key in event_dict - ] - - if context_parts: + if context_parts := [ + f"{key}={event_dict[key]}" + for key in _RICH_CONTEXT_KEYS + if key in event_dict + ]: # Use pipe separator - brackets would be interpreted as Rich markup return f"{event} | {' '.join(context_parts)}" return event diff --git a/src/noteflow/infrastructure/logging/processors.py b/src/noteflow/infrastructure/logging/processors.py index 33df396..4618056 100644 --- a/src/noteflow/infrastructure/logging/processors.py +++ b/src/noteflow/infrastructure/logging/processors.py @@ -93,9 +93,7 @@ def _extract_otel_context() -> tuple[int, int] | None: if not span.is_recording(): return None ctx = span.get_span_context() - if not ctx.is_valid: - return None - return ctx.trace_id, ctx.span_id + return (ctx.trace_id, ctx.span_id) if ctx.is_valid else None except (AttributeError, TypeError): # Graceful degradation for edge cases return None diff --git a/src/noteflow/infrastructure/persistence/_migrations/_alembic_commands.py b/src/noteflow/infrastructure/persistence/_migrations/_alembic_commands.py index 76eae57..fe7e2d1 100644 --- a/src/noteflow/infrastructure/persistence/_migrations/_alembic_commands.py +++ b/src/noteflow/infrastructure/persistence/_migrations/_alembic_commands.py @@ -22,10 +22,14 @@ _PROJECT_ROOT_MARKERS: Final[tuple[str, ...]] = ("alembic.ini", "pyproject.toml" def _find_marker_in_directory(directory: Path) -> str | None: """Check if any project root marker exists in the directory.""" - for marker in _PROJECT_ROOT_MARKERS: - if (directory / marker).exists(): - return marker - return None + return next( + ( + marker + for marker in _PROJECT_ROOT_MARKERS + if (directory / marker).exists() + ), + None, + ) def _get_project_root() -> Path: diff --git a/src/noteflow/infrastructure/persistence/repositories/entity_repo.py b/src/noteflow/infrastructure/persistence/repositories/entity_repo.py index 0237fef..439c204 100644 --- a/src/noteflow/infrastructure/persistence/repositories/entity_repo.py +++ b/src/noteflow/infrastructure/persistence/repositories/entity_repo.py @@ -123,8 +123,7 @@ class SqlAlchemyEntityRepository( NamedEntityModel.normalized_text, ) result = await self._session.execute(stmt) - rows = result.all() - if rows: + if rows := result.all(): ids_by_key = { (str(row.meeting_id), row.normalized_text): row.id for row in rows diff --git a/src/noteflow/infrastructure/platform/__init__.py b/src/noteflow/infrastructure/platform/__init__.py index 2544d95..d7e205a 100644 --- a/src/noteflow/infrastructure/platform/__init__.py +++ b/src/noteflow/infrastructure/platform/__init__.py @@ -33,9 +33,7 @@ def _read_sysctl_features() -> str | None: ) except (OSError, subprocess.SubprocessError): return None - if result.returncode != 0: - return None - return result.stdout + return None if result.returncode != 0 else result.stdout @cache @@ -53,11 +51,7 @@ def has_avx2_support() -> bool: return "avx2" in cpuinfo.lower() features = _read_sysctl_features() - if features is not None: - return "avx2" in features.lower() - - # Default to False (conservative - will disable NNPACK) - return False + return "avx2" in features.lower() if features is not None else False def configure_pytorch_for_platform() -> None: