From 038fac48f9c43bd14c92c17e98532d19b7443329 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Mon, 7 Feb 2022 21:02:28 +0100 Subject: [PATCH] Fix a bug with an uninitialized attribute --- channel.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/channel.py b/channel.py index 97f5df9..dd3ad3f 100644 --- a/channel.py +++ b/channel.py @@ -52,8 +52,7 @@ class Stream: class Channel: def __init__(self, twitch: Twitch, data: JsonType, *, priority: bool = False): - self._twitch: Twitch = twitch - self._gui_channels: ChannelList = twitch.gui.channels + self._init_base(twitch) self.id: int = int(data["id"]) self._login: str = data["name"] self._display_name: Optional[str] = data.get("displayName") @@ -67,6 +66,10 @@ class Channel: # • not cleaned up unless they're streaming a game we haven't selected self.priority: bool = priority + def _init_base(self, twitch: Twitch): + self._twitch: Twitch = twitch + self._gui_channels: ChannelList = twitch.gui.channels + @property def name(self) -> str: if self._display_name is not None: @@ -80,7 +83,7 @@ class Channel: @classmethod def from_directory(cls, twitch: Twitch, data: JsonType, *, priority: bool = False) -> Channel: self = super().__new__(cls) - self._twitch = twitch + self._init_base(twitch) channel = data["broadcaster"] self.id = int(channel["id"]) self._login = channel["login"] @@ -97,7 +100,7 @@ class Channel: cls, twitch: Twitch, channel_login: str, *, priority: bool = False ) -> Channel: self = super().__new__(cls) - self._twitch = twitch + self._init_base(twitch) # id and display name to be filled by get_stream self._login = channel_login self._spade_url = None