Remove channel type coercion in factory methods
This caused unnecessary isinstance checks which were slowing down channel creation at scale
This commit is contained in:
parent
03cd6ff433
commit
74e1ab09a0
@ -1892,14 +1892,8 @@ class GroupChannel(discord.abc.Messageable, Hashable):
|
|||||||
await self._state.http.leave_group(self.id)
|
await self._state.http.leave_group(self.id)
|
||||||
|
|
||||||
|
|
||||||
def _coerce_channel_type(value: Union[ChannelType, int]) -> ChannelType:
|
def _guild_channel_factory(channel_type: int):
|
||||||
if isinstance(value, ChannelType):
|
value = try_enum(ChannelType, channel_type)
|
||||||
return value
|
|
||||||
return try_enum(ChannelType, value)
|
|
||||||
|
|
||||||
|
|
||||||
def _guild_channel_factory(channel_type: Union[ChannelType, int]):
|
|
||||||
value = _coerce_channel_type(channel_type)
|
|
||||||
if value is ChannelType.text:
|
if value is ChannelType.text:
|
||||||
return TextChannel, value
|
return TextChannel, value
|
||||||
elif value is ChannelType.voice:
|
elif value is ChannelType.voice:
|
||||||
@ -1916,7 +1910,7 @@ def _guild_channel_factory(channel_type: Union[ChannelType, int]):
|
|||||||
return None, value
|
return None, value
|
||||||
|
|
||||||
|
|
||||||
def _channel_factory(channel_type: Union[ChannelType, int]):
|
def _channel_factory(channel_type: int):
|
||||||
cls, value = _guild_channel_factory(channel_type)
|
cls, value = _guild_channel_factory(channel_type)
|
||||||
if value is ChannelType.private:
|
if value is ChannelType.private:
|
||||||
return DMChannel, value
|
return DMChannel, value
|
||||||
@ -1925,7 +1919,7 @@ def _channel_factory(channel_type: Union[ChannelType, int]):
|
|||||||
else:
|
else:
|
||||||
return cls, value
|
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)
|
cls, value = _channel_factory(channel_type)
|
||||||
if value in (ChannelType.private_thread, ChannelType.public_thread, ChannelType.news_thread):
|
if value in (ChannelType.private_thread, ChannelType.public_thread, ChannelType.news_thread):
|
||||||
return Thread, value
|
return Thread, value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user