From 32f475d7ed4fc03c0e892644f24a7a61c172a77c Mon Sep 17 00:00:00 2001 From: DevilXD Date: Sun, 6 Feb 2022 21:05:37 +0100 Subject: [PATCH] Fix the possibility of stream_data being None --- channel.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/channel.py b/channel.py index 4fa3d62..469e277 100644 --- a/channel.py +++ b/channel.py @@ -212,17 +212,20 @@ class Channel: return match.group(1) async def get_stream(self) -> Optional[Stream]: - response = await self._twitch.gql_request( + response: Optional[JsonType] = await self._twitch.gql_request( GQL_OPERATIONS["GetStreamInfo"].with_variables({"channel": self._login}) ) - if response: - stream_data = response["data"]["user"] - # fill channel_id and display name - self.id = int(stream_data["id"]) - self._display_name = stream_data["displayName"] - if stream_data["stream"]: - return Stream(self, stream_data) - return None + if not response: + return None + stream_data: Optional[JsonType] = response["data"]["user"] + if not stream_data: + return None + # fill in channel_id and display name + self.id = int(stream_data["id"]) + self._display_name = stream_data["displayName"] + if not stream_data["stream"]: + return None + return Stream(self, stream_data) async def check_online(self) -> bool: stream = await self.get_stream()