Skip to content

Commit f6114bf

Browse files
authored
Fixed typing warnings in run_tribler (#8406)
2 parents 96a0857 + 50bf1b9 commit f6114bf

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/run_tribler.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
import sys
44
import traceback
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, overload
66

77
if TYPE_CHECKING:
8+
from typing import Literal, NoReturn
9+
810
from pystray import Icon
911

1012

11-
def show_error(exc: Exception, shutdown: bool = True) -> None:
13+
@overload
14+
def show_error(exc: Exception, shutdown: Literal[True] = True) -> NoReturn:
15+
...
16+
17+
18+
@overload
19+
def show_error(exc: Exception, shutdown: Literal[False] = True) -> None:
20+
...
21+
22+
23+
def show_error(exc: Exception, shutdown: bool = True) -> NoReturn:
1224
"""
1325
Create a native pop-up without any third party dependency.
1426
@@ -51,7 +63,6 @@ def show_error(exc: Exception, shutdown: bool = True) -> None:
5163
import encodings.idna # noqa: F401 (https://github.com/pyinstaller/pyinstaller/issues/1113)
5264
import logging.config
5365
import os
54-
import sys
5566
import threading
5667
import typing
5768
import webbrowser
@@ -65,7 +76,7 @@ def show_error(exc: Exception, shutdown: bool = True) -> None:
6576
from tribler.tribler_config import VERSION_SUBDIR, TriblerConfigManager
6677

6778
except Exception as e:
68-
show_error(e)
79+
show_error(e, True)
6980

7081
logger = logging.getLogger(__name__)
7182

@@ -77,6 +88,7 @@ class Arguments(typing.TypedDict):
7788

7889
torrent: str
7990
log_level: str
91+
server: bool
8092

8193

8294
def parse_args() -> Arguments:
@@ -220,7 +232,7 @@ async def main() -> None:
220232
torrent_uri = load_torrent_uri(parsed_args)
221233
server_url = await session.find_api_server()
222234

223-
headless = parsed_args.get('server')
235+
headless = parsed_args.get("server")
224236
if server_url:
225237
logger.info("Core already running at %s", server_url)
226238
if torrent_uri:
@@ -233,17 +245,16 @@ async def main() -> None:
233245

234246
await session.start()
235247
except Exception as exc:
236-
show_error(exc)
248+
show_error(exc, True)
237249

238250
server_url = await session.find_api_server()
239251
if server_url and torrent_uri:
240252
await start_download(config, server_url, torrent_uri)
241-
if not headless:
242-
icon = spawn_tray_icon(session, config)
253+
icon = None if headless else spawn_tray_icon(session, config)
243254

244255
await session.shutdown_event.wait()
245256
await session.shutdown()
246-
if not headless:
257+
if icon:
247258
icon.stop()
248259
logger.info("Tribler shutdown completed")
249260

0 commit comments

Comments
 (0)