From 7ba6f434cac8d07c7e9141101f2adcd43d1a9ad7 Mon Sep 17 00:00:00 2001 From: linuxdaemon Date: Thu, 18 Apr 2024 15:58:48 +0000 Subject: [PATCH] refactor: replace old-style type comments with annotations --- plugins/core/cap.py | 2 +- plugins/core/chan_track.py | 12 +++++------- plugins/duckhunt.py | 2 +- plugins/tvdb.py | 8 ++++---- plugins/weather.py | 2 +- plugins/youtube.py | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/core/cap.py b/plugins/core/cap.py index 77ceec53a..c77fa16b2 100644 --- a/plugins/core/cap.py +++ b/plugins/core/cap.py @@ -20,7 +20,7 @@ def send_cap_ls(conn): async def handle_available_caps(conn, caplist, event, irc_paramlist, bot): - available_caps = conn.memory["available_caps"] # type: CapList + available_caps: CapList = conn.memory["available_caps"] available_caps.extend(caplist) cap_queue = conn.memory["cap_queue"] for cap in caplist: diff --git a/plugins/core/chan_track.py b/plugins/core/chan_track.py index de29de3eb..52bab88f9 100644 --- a/plugins/core/chan_track.py +++ b/plugins/core/chan_track.py @@ -282,8 +282,7 @@ def get_chans(conn): # endregion util functions -def update_chan_data(conn, chan): - # type: (IrcClient, str) -> None +def update_chan_data(conn: IrcClient, chan: str) -> None: """ Start the process of updating channel data from /NAMES :param conn: The current connection @@ -294,8 +293,7 @@ def update_chan_data(conn, chan): conn.cmd("NAMES", chan) -def update_conn_data(conn): - # type: (IrcClient) -> None +def update_conn_data(conn: IrcClient) -> None: """ Update all channel data for this connection :param conn: The connection to update @@ -585,7 +583,7 @@ def handle_tags(conn: IrcClient, nick: str, irc_tags: TagList) -> None: users = get_users(conn) if irc_tags: - account_tag = irc_tags.get("account") # type: MessageTag + account_tag: MessageTag = irc_tags.get("account") if account_tag: user_data = users.getuser(nick) user_data.account = account_tag.value @@ -659,8 +657,8 @@ def on_mode(chan, irc_paramlist, conn): return serv_info = conn.memory["server_info"] - statuses = serv_info["statuses"] # type: Dict[str, StatusMode] - mode_types = serv_info["channel_modes"] # type: Dict[str, ChannelMode] + statuses: Dict[str, StatusMode] = serv_info["statuses"] + mode_types: Dict[str, ChannelMode] = serv_info["channel_modes"] chan_data = get_chans(conn).getchan(chan) diff --git a/plugins/duckhunt.py b/plugins/duckhunt.py index f35385af4..a4acbf6fc 100644 --- a/plugins/duckhunt.py +++ b/plugins/duckhunt.py @@ -262,7 +262,7 @@ def start_hunt(db, chan, message, conn): def set_ducktime(chan, conn): - status = get_state_table(conn, chan) # type: ChannelState + status: ChannelState = get_state_table(conn, chan) status.next_duck_time = random.randint( int(time()) + 480, int(time()) + 3600 ) diff --git a/plugins/tvdb.py b/plugins/tvdb.py index 533bc7a75..f2240f01b 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -43,14 +43,14 @@ class NoMatchingSeries(LookupError): class TvdbApi: def __init__(self) -> None: self.token_lifetime = token_lifetime - self._headers = None # type: Optional[Dict[str, str]] + self._headers: Optional[Dict[str, str]] = None self.base_url = "https://api.thetvdb.com" self.api_version = "3.0.0" self.default_headers = { "Accept": f"application/vnd.thetvdb.v{self.api_version}" } - self.jwt_token = None # type: Optional[str] + self.jwt_token: Optional[str] = None self.refresh_time = datetime.datetime.min @property @@ -209,7 +209,7 @@ class Holder(Generic[T]): """ def __init__(self) -> None: - self._item = None # type: Optional[T] + self._item: Optional[T] = None self._set = False def set(self, item: T) -> None: @@ -284,7 +284,7 @@ class LazyCollection(Sized, Iterable[T], Container[T]): """ def __init__(self, it: Iterable[T]) -> None: - self._data = [] # type: List[T] + self._data: List[T] = [] self._it = iter(it) self._complete = False diff --git a/plugins/weather.py b/plugins/weather.py index 98ddb5ecd..3fb472c63 100644 --- a/plugins/weather.py +++ b/plugins/weather.py @@ -16,7 +16,7 @@ class PluginData: - maps_api = None # type: Api + maps_api: Api = None owm_api: Optional[OWM] = None diff --git a/plugins/youtube.py b/plugins/youtube.py index 589434415..e11c2decd 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -184,7 +184,7 @@ def get_video_id(text: str) -> str: if not json.get("items"): raise NoResultsError(request) - video_id = json["items"][0]["id"]["videoId"] # type: str + video_id: str = json["items"][0]["id"]["videoId"] return video_id