aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-07-05 22:13:10 -0400
committerRapptz <[email protected]>2021-07-07 20:19:17 -0400
commit74e1ab09a0af178071903c117418853638357793 (patch)
tree59a6c4aa9ead4678c5cc124e07ee02a064357a4b
parentRemove calls to gc.collect in ConnectionState (diff)
downloaddiscord.py-74e1ab09a0af178071903c117418853638357793.tar.xz
discord.py-74e1ab09a0af178071903c117418853638357793.zip
Remove channel type coercion in factory methods
This caused unnecessary isinstance checks which were slowing down channel creation at scale
-rw-r--r--discord/channel.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/discord/channel.py b/discord/channel.py
index dbe8533f..18c26fdf 100644
--- a/discord/channel.py
+++ b/discord/channel.py
@@ -1892,14 +1892,8 @@ class GroupChannel(discord.abc.Messageable, Hashable):
await self._state.http.leave_group(self.id)
-def _coerce_channel_type(value: Union[ChannelType, int]) -> ChannelType:
- if isinstance(value, ChannelType):
- return value
- return try_enum(ChannelType, value)
-
-
-def _guild_channel_factory(channel_type: Union[ChannelType, int]):
- value = _coerce_channel_type(channel_type)
+def _guild_channel_factory(channel_type: int):
+ value = try_enum(ChannelType, channel_type)
if value is ChannelType.text:
return TextChannel, value
elif value is ChannelType.voice:
@@ -1916,7 +1910,7 @@ def _guild_channel_factory(channel_type: Union[ChannelType, int]):
return None, value
-def _channel_factory(channel_type: Union[ChannelType, int]):
+def _channel_factory(channel_type: int):
cls, value = _guild_channel_factory(channel_type)
if value is ChannelType.private:
return DMChannel, value
@@ -1925,7 +1919,7 @@ def _channel_factory(channel_type: Union[ChannelType, int]):
else:
return cls, value
-def _threaded_channel_factory(channel_type: Union[ChannelType, int]):
+def _threaded_channel_factory(channel_type: int):
cls, value = _channel_factory(channel_type)
if value in (ChannelType.private_thread, ChannelType.public_thread, ChannelType.news_thread):
return Thread, value