Skip to content

Commit 87885e9

Browse files
committed
refactor(macOS): migrate Optional/Union to modern union syntax
Replace typing.Optional and typing.Union with X | None across the omlx_app package. Update Callable imports to collections.abc.
1 parent e1b3a44 commit 87885e9

5 files changed

Lines changed: 23 additions & 25 deletions

File tree

packaging/omlx_app/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import logging
55
from dataclasses import dataclass, asdict
66
from pathlib import Path
7-
from typing import Optional
87

98
import requests
109

@@ -79,7 +78,7 @@ def load(cls) -> "ServerConfig":
7978
pass
8079
return cls()
8180

82-
def get_server_api_key(self) -> Optional[str]:
81+
def get_server_api_key(self) -> str | None:
8382
"""Read the API key from the server's settings.json."""
8483
settings_file = Path(self.base_path).expanduser() / "settings.json"
8584
if settings_file.exists():

packaging/omlx_app/preferences.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import plistlib
55
import shutil
66
from pathlib import Path
7-
from typing import Callable, Optional
7+
from collections.abc import Callable
88

99
import objc
1010
from AppKit import (
@@ -61,8 +61,8 @@ def initWithConfig_serverManager_onSave_(
6161
return None
6262
self.config = config
6363
self.server_manager = server_manager
64-
self.on_save: Optional[Callable] = on_save_callback
65-
self.show_welcome: Optional[Callable] = None
64+
self.on_save: Callable | None = on_save_callback
65+
self.show_welcome: Callable | None = None
6666
self.window = None
6767
self.launch_at_login_checkbox = None
6868
self.auto_start_checkbox = None
@@ -638,7 +638,7 @@ def resetSettings_(self, sender):
638638
if self.on_save:
639639
self.on_save()
640640

641-
def _get_app_path(self) -> Optional[str]:
641+
def _get_app_path(self) -> str | None:
642642
"""Find the oMLX.app bundle path."""
643643
app_py = Path(__file__)
644644
for parent in app_py.parents:

packaging/omlx_app/server_manager.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from dataclasses import dataclass
1212
from enum import Enum
1313
from pathlib import Path
14-
from typing import Callable, Optional, Union
14+
from collections.abc import Callable
1515

1616
import requests
1717

@@ -32,7 +32,7 @@ class ServerStatus(Enum):
3232
@dataclass
3333
class PortConflict:
3434
"""Returned by start() when the port is already in use."""
35-
pid: Optional[int]
35+
pid: int | None
3636
is_omlx: bool
3737

3838

@@ -58,12 +58,12 @@ class ServerManager:
5858

5959
def __init__(self, config: ServerConfig):
6060
self.config = config
61-
self._process: Optional[subprocess.Popen] = None
61+
self._process: subprocess.Popen | None = None
6262
self._status = ServerStatus.STOPPED
63-
self._error_message: Optional[str] = None
63+
self._error_message: str | None = None
6464
self._log_file_handle = None
65-
self._status_callback: Optional[Callable[[ServerStatus], None]] = None
66-
self._health_check_thread: Optional[threading.Thread] = None
65+
self._status_callback: Callable[[ServerStatus], None] | None = None
66+
self._health_check_thread: threading.Thread | None = None
6767
self._stop_health_check = threading.Event()
6868
self._adopted = False
6969

@@ -82,13 +82,13 @@ def status(self) -> ServerStatus:
8282
return self._status
8383

8484
@property
85-
def error_message(self) -> Optional[str]:
85+
def error_message(self) -> str | None:
8686
return self._error_message
8787

8888
def set_status_callback(self, callback: Callable[[ServerStatus], None]) -> None:
8989
self._status_callback = callback
9090

91-
def _update_status(self, status: ServerStatus, error: Optional[str] = None) -> None:
91+
def _update_status(self, status: ServerStatus, error: str | None = None) -> None:
9292
self._status = status
9393
self._error_message = error
9494
if self._status_callback:
@@ -237,7 +237,7 @@ def _is_omlx_server(self) -> bool:
237237
except requests.RequestException:
238238
return False
239239

240-
def _find_port_owner_pid(self) -> Optional[int]:
240+
def _find_port_owner_pid(self) -> int | None:
241241
"""Find the PID of the process listening on the configured port."""
242242
try:
243243
result = subprocess.run(
@@ -290,7 +290,7 @@ def adopt(self) -> bool:
290290
logger.info(f"Adopted external oMLX server on port {self.config.port}")
291291
return True
292292

293-
def _do_start(self) -> Union[bool, PortConflict]:
293+
def _do_start(self) -> bool | PortConflict:
294294
"""Core start logic shared by start() and auto-restart.
295295
296296
Does NOT check current status or start the health check thread.
@@ -331,7 +331,7 @@ def _do_start(self) -> Union[bool, PortConflict]:
331331
logger.error(f"Failed to start server: {e}")
332332
return False
333333

334-
def start(self) -> Union[bool, PortConflict]:
334+
def start(self) -> bool | PortConflict:
335335
if self._status in (ServerStatus.RUNNING, ServerStatus.STARTING):
336336
return False
337337

@@ -352,7 +352,7 @@ def start(self) -> Union[bool, PortConflict]:
352352

353353
return result
354354

355-
def force_restart(self) -> Union[bool, PortConflict]:
355+
def force_restart(self) -> bool | PortConflict:
356356
"""Force restart: kill process, reset counters, and start fresh."""
357357
self._cleanup_dead_process()
358358
self._auto_restart_count = 0
@@ -422,7 +422,7 @@ def stop(self, timeout: float = 10.0) -> bool:
422422
self._update_status(ServerStatus.ERROR, str(e))
423423
return False
424424

425-
def restart(self) -> Union[bool, PortConflict]:
425+
def restart(self) -> bool | PortConflict:
426426
self.stop()
427427
import time
428428
time.sleep(1)

packaging/omlx_app/updater.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import tempfile
1313
import threading
1414
from pathlib import Path
15-
from typing import Callable, Optional
15+
from collections.abc import Callable
1616

1717
import requests
1818

@@ -34,9 +34,9 @@ def __init__(
3434
self,
3535
dmg_url: str,
3636
version: str,
37-
on_progress: Optional[Callable[[str], None]] = None,
38-
on_error: Optional[Callable[[str], None]] = None,
39-
on_ready: Optional[Callable[[], None]] = None,
37+
on_progress: Callable[[str], None] | None = None,
38+
on_error: Callable[[str], None] | None = None,
39+
on_ready: Callable[[], None] | None = None,
4040
):
4141
self.dmg_url = dmg_url
4242
self.version = version

packaging/omlx_app/welcome.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import webbrowser
55
from pathlib import Path
6-
from typing import Optional
76

87
import objc
98
from AppKit import (
@@ -64,7 +63,7 @@ def initWithConfig_serverManager_(self, config, server_manager):
6463
self.status_check_timer = None
6564
return self
6665

67-
def _get_logo_path(self) -> Optional[Path]:
66+
def _get_logo_path(self) -> Path | None:
6867
"""Find the logo SVG file."""
6968
svg_name = "navbar-logo-dark.svg"
7069
bundle_res = Path(__file__).parent.parent

0 commit comments

Comments
 (0)