Browse Source

Don't use abc.PrivateChannel in type hints

pull/10109/head
dolfies 2 years ago
parent
commit
3e3cf05423
  1. 4
      discord/client.py
  2. 6
      discord/invite.py
  3. 5
      discord/settings.py
  4. 9
      discord/state.py

4
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',

6
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

5
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',

9
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)

Loading…
Cancel
Save