From 229c54a4f1fc68f0d7346191347233ebc127108d Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Thu, 8 Apr 2021 16:06:11 +0200 Subject: [PATCH] Set `type` attribute for channels to proper enum members for easier narrowing (#67) --- discord-stubs/channel.pyi | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/discord-stubs/channel.pyi b/discord-stubs/channel.pyi index 2ce9183..8a5aeae 100644 --- a/discord-stubs/channel.pyi +++ b/discord-stubs/channel.pyi @@ -1,5 +1,6 @@ import datetime from typing import Callable, Dict, Iterable, List, Optional, Union, overload +from typing_extensions import Literal import discord.abc @@ -21,7 +22,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): slowmode_delay: int nsfw: bool @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.text, ChannelType.news]: ... def permissions_for(self, member: Member) -> Permissions: ... @property def members(self) -> List[Member]: ... @@ -80,7 +81,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha class VoiceChannel(VocalGuildChannel): @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.voice]: ... async def edit( self, *, @@ -100,7 +101,7 @@ class StageChannel(VocalGuildChannel): @property def requesting_to_speak(self) -> List[Member]: ... @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.stage_voice]: ... async def edit( self, *, @@ -117,7 +118,7 @@ class StageChannel(VocalGuildChannel): class CategoryChannel(discord.abc.GuildChannel, Hashable): nsfw: bool @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.category]: ... def is_nsfw(self) -> bool: ... async def edit( self, @@ -212,7 +213,7 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): class StoreChannel(discord.abc.GuildChannel, Hashable): nsfw: bool @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.store]: ... def permissions_for(self, member: Member) -> Permissions: ... def is_nsfw(self) -> bool: ... async def edit( @@ -232,7 +233,7 @@ class DMChannel(discord.abc.Messageable, Hashable): recipient: User me: ClientUser @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.private]: ... @property def created_at(self) -> datetime.datetime: ... def permissions_for(self, user: Optional[BaseUser] = ...) -> Permissions: ... @@ -246,7 +247,7 @@ class GroupChannel(discord.abc.Messageable, Hashable): name: Optional[str] recipients: List[User] @property - def type(self) -> ChannelType: ... + def type(self) -> Literal[ChannelType.group]: ... @property def icon_url(self) -> Asset: ... def icon_url_as(