chore: mypy for __main__ (#1853)
authorJc2k <john.carr@unrouted.co.uk>
Fri, 10 Jan 2025 22:47:53 +0000 (22:47 +0000)
committerGitHub <noreply@github.com>
Fri, 10 Jan 2025 22:47:53 +0000 (23:47 +0100)
music_assistant/__main__.py
pyproject.toml

index 1e989c65ebff8db3483a6ad0785f09ad49f3115f..d3db29cd397ba686e8c51006cc9ceaaf2c1efcf6 100644 (file)
@@ -17,10 +17,10 @@ from typing import Any, Final
 from aiorun import run
 from colorlog import ColoredFormatter
 
-from music_assistant import MusicAssistant
 from music_assistant.constants import MASS_LOGGER_NAME, VERBOSE_LOG_LEVEL
 from music_assistant.helpers.json import json_loads
 from music_assistant.helpers.logging import activate_log_queue_handler
+from music_assistant.mass import MusicAssistant
 
 FORMAT_DATE: Final = "%Y-%m-%d"
 FORMAT_TIME: Final = "%H:%M:%S"
@@ -31,11 +31,13 @@ ALPINE_RELEASE_FILE = "/etc/alpine-release"
 LOGGER = logging.getLogger(MASS_LOGGER_NAME)
 
 
-def get_arguments():
+def get_arguments() -> argparse.Namespace:
     """Arguments handling."""
     parser = argparse.ArgumentParser(description="MusicAssistant")
 
     default_data_dir = os.getenv("APPDATA") if os.name == "nt" else os.path.expanduser("~")
+    if not default_data_dir:
+        parser.error("Unable to find default data dir")
     default_data_dir = os.path.join(default_data_dir, ".musicassistant")
 
     parser.add_argument(
@@ -60,7 +62,7 @@ def get_arguments():
     return parser.parse_args()
 
 
-def setup_logger(data_path: str, level: str = "DEBUG"):
+def setup_logger(data_path: str, level: str = "DEBUG") -> logging.Logger:
     """Initialize logger."""
     # define log formatter
     log_fmt = "%(asctime)s.%(msecs)03d %(levelname)s (%(threadName)s) [%(name)s] %(message)s"
@@ -118,7 +120,7 @@ def setup_logger(data_path: str, level: str = "DEBUG"):
 
     sys.excepthook = lambda *args: logging.getLogger(None).exception(
         "Uncaught exception",
-        exc_info=args,  # type: ignore[arg-type]
+        exc_info=args,
     )
     threading.excepthook = lambda args: logging.getLogger(None).exception(
         "Uncaught thread exception",
@@ -141,7 +143,7 @@ def _enable_posix_spawn() -> None:
     # and will use fork() instead of posix_spawn() which significantly
     # less efficient. This is a workaround to force posix_spawn()
     # on Alpine Linux which is supported by musl.
-    subprocess._USE_POSIX_SPAWN = os.path.exists(ALPINE_RELEASE_FILE)
+    subprocess._USE_POSIX_SPAWN = os.path.exists(ALPINE_RELEASE_FILE)  # type: ignore[misc]
 
 
 def _global_loop_exception_handler(_: Any, context: dict[str, Any]) -> None:
@@ -198,7 +200,7 @@ def main() -> None:
     # enable alpine subprocess workaround
     _enable_posix_spawn()
 
-    def on_shutdown(loop) -> None:
+    def on_shutdown(loop: asyncio.AbstractEventLoop) -> None:
         logger.info("shutdown requested!")
         loop.run_until_complete(mass.stop())
 
index 7686e9b037bee1256c1e774b73c63d7a773d51b8..a4d60c8c214296ffbbc0cbbd904e5e63d284fc0e 100644 (file)
@@ -123,7 +123,6 @@ exclude = [
   '^music_assistant/helpers/.*$',
   '^music_assistant/models/.*$',
   '^music_assistant/mass\.py$',
-  '^music_assistant/__main__\.py$',
   '^music_assistant/providers/_template_music_provider/.*$',
   '^music_assistant/providers/_template_player_provider/.*$',
   '^music_assistant/providers/apple_music/.*$',