From 3e3cf05423ea68538c031e9676f118b215b1d2bc Mon Sep 17 00:00:00 2001 From: dolfies Date: Wed, 5 Apr 2023 17:47:03 -0400 Subject: [PATCH] Don't use abc.PrivateChannel in type hints --- discord/client.py | 4 +++- discord/invite.py | 6 +++--- discord/settings.py | 5 ++++- discord/state.py | 9 +++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/discord/client.py b/discord/client.py index 3ab59f94f..3b5b948b7 100644 --- a/discord/client.py +++ b/discord/client.py @@ -93,7 +93,7 @@ if TYPE_CHECKING: from typing_extensions import Self from types import TracebackType from .guild import GuildChannel - from .abc import PrivateChannel, Snowflake, SnowflakeTime + from .abc import Snowflake, SnowflakeTime from .channel import DMChannel from .message import Message from .member import Member @@ -104,6 +104,8 @@ if TYPE_CHECKING: from .metadata import MetadataObject from .types.snowflake import Snowflake as _Snowflake + PrivateChannel = Union[DMChannel, GroupChannel] + # fmt: off __all__ = ( 'Client', diff --git a/discord/invite.py b/discord/invite.py index f8eae7925..65f83f915 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -52,14 +52,14 @@ if TYPE_CHECKING: ) from .state import ConnectionState from .guild import Guild - from .abc import GuildChannel, PrivateChannel, Snowflake - from .channel import GroupChannel + from .abc import GuildChannel, Snowflake + from .channel import DMChannel, GroupChannel from .user import User from .application import PartialApplication from .message import Message InviteGuildType = Union[Guild, 'PartialInviteGuild', Object] - InviteChannelType = Union[GuildChannel, 'PartialInviteChannel', Object, PrivateChannel] + InviteChannelType = Union[GuildChannel, 'PartialInviteChannel', Object, DMChannel, GroupChannel] import datetime diff --git a/discord/settings.py b/discord/settings.py index 043586d1e..b9437584e 100644 --- a/discord/settings.py +++ b/discord/settings.py @@ -57,11 +57,14 @@ if TYPE_CHECKING: from google.protobuf.message import Message from typing_extensions import Self - from .abc import GuildChannel, PrivateChannel, Snowflake + from .abc import GuildChannel, Snowflake + from .channel import DMChannel, GroupChannel from .guild import Guild from .state import ConnectionState from .user import ClientUser, User + PrivateChannel = Union[DMChannel, GroupChannel] + __all__ = ( 'UserSettings', 'GuildFolder', diff --git a/discord/state.py b/discord/state.py index 622683c12..47273c57a 100644 --- a/discord/state.py +++ b/discord/state.py @@ -98,7 +98,7 @@ from .audit_logs import AuditLogEntry if TYPE_CHECKING: from typing_extensions import Self - from .abc import PrivateChannel, Snowflake as abcSnowflake + from .abc import Snowflake as abcSnowflake from .activity import ActivityTypes from .message import MessageableChannel from .guild import GuildChannel @@ -123,6 +123,7 @@ if TYPE_CHECKING: from .types.activity import ClientStatus as ClientStatusPayload T = TypeVar('T') + PrivateChannel = Union[DMChannel, GroupChannel] Channel = Union[GuildChannel, PrivateChannel, PartialMessageable] MISSING = utils.MISSING @@ -689,7 +690,7 @@ class ConnectionState: ) -> Tuple[Optional[User], VoiceState, VoiceState]: user_id = int(data['user_id']) user = self.get_user(user_id) - channel: Optional[Union[DMChannel, GroupChannel]] = self._get_private_channel(channel_id) # type: ignore + channel: Optional[Union[DMChannel, GroupChannel]] = self._get_private_channel(channel_id) try: # Check if we should remove the voice state from cache @@ -1489,7 +1490,7 @@ class ConnectionState: channel = self._get_private_channel(channel_id) if channel is not None: old_channel = copy.copy(channel) - channel._update(data) + channel._update(data) # type: ignore # the data payload varies based on the channel type self.dispatch('private_channel_update', old_channel, channel) return else: @@ -1501,7 +1502,7 @@ class ConnectionState: channel = guild.get_channel(channel_id) if channel is not None: old_channel = copy.copy(channel) - channel._update(guild, data) # type: ignore # the data payload varies based on the channel type. + channel._update(guild, data) # type: ignore # the data payload varies based on the channel type self.dispatch('guild_channel_update', old_channel, channel) else: _log.debug('CHANNEL_UPDATE referencing an unknown channel ID: %s. Discarding.', channel_id)