From 373b727084d211ed8f8d05dc6f6ec59cd033847e Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 May 2020 11:39:21 -0300 Subject: [PATCH] Add helper bool magic method for state validity Reported in #102 --- litecord/gateway/state.py | 4 ++++ litecord/pubsub/lazy_guild.py | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/litecord/gateway/state.py b/litecord/gateway/state.py index 3bac060..eb2925e 100644 --- a/litecord/gateway/state.py +++ b/litecord/gateway/state.py @@ -94,5 +94,9 @@ class GatewayState: self.large: int = kwargs.get("large") or 50 + def __bool__(self): + """Return if the given state is a valid state to be used.""" + return self.ws is not None + def __repr__(self): return f"GatewayState" diff --git a/litecord/pubsub/lazy_guild.py b/litecord/pubsub/lazy_guild.py index 38198ef..5bc2d38 100644 --- a/litecord/pubsub/lazy_guild.py +++ b/litecord/pubsub/lazy_guild.py @@ -593,10 +593,7 @@ class GuildMemberList: dispatched = [] for state in states: - if state is None: - continue - - if state.ws is None: + if not state: continue await state.ws.dispatch("GUILD_MEMBER_LIST_UPDATE", payload)