Browse Source

Update Pyright to v1.1.394

pull/10107/head
Rapptz 1 month ago
parent
commit
8953938a53
  1. 2
      .github/workflows/lint.yml
  2. 7
      discord/abc.py
  3. 10
      discord/activity.py
  4. 8
      discord/app_commands/commands.py
  5. 2
      discord/app_commands/transformers.py
  6. 2
      discord/app_commands/tree.py
  7. 6
      discord/components.py
  8. 12
      discord/enums.py
  9. 4
      discord/ext/commands/bot.py
  10. 2
      discord/ext/commands/context.py
  11. 6
      discord/ext/commands/converter.py
  12. 2
      discord/ext/commands/core.py
  13. 7
      discord/ext/commands/errors.py
  14. 2
      discord/ext/commands/flags.py
  15. 13
      discord/ext/commands/hybrid.py
  16. 4
      discord/gateway.py
  17. 5
      discord/guild.py
  18. 5
      discord/interactions.py
  19. 2
      discord/invite.py
  20. 6
      discord/member.py
  21. 23
      discord/message.py
  22. 14
      discord/raw_models.py
  23. 2
      discord/role.py
  24. 8
      discord/state.py
  25. 2
      discord/threads.py
  26. 4
      discord/types/guild.py
  27. 5
      discord/ui/select.py
  28. 2
      discord/ui/view.py
  29. 6
      discord/utils.py
  30. 2
      discord/widget.py

2
.github/workflows/lint.yml

@ -38,7 +38,7 @@ jobs:
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
version: '1.1.351'
version: '1.1.394'
warnings: false
no-comments: ${{ matrix.python-version != '3.x' }}

7
discord/abc.py

@ -102,6 +102,9 @@ if TYPE_CHECKING:
GuildChannel as GuildChannelPayload,
OverwriteType,
)
from .types.guild import (
ChannelPositionUpdate,
)
from .types.snowflake import (
SnowflakeList,
)
@ -1232,11 +1235,11 @@ class GuildChannel:
raise ValueError('Could not resolve appropriate move position')
channels.insert(max((index + offset), 0), self)
payload = []
payload: List[ChannelPositionUpdate] = []
lock_permissions = kwargs.get('sync_permissions', False)
reason = kwargs.get('reason')
for index, channel in enumerate(channels):
d = {'id': channel.id, 'position': index}
d: ChannelPositionUpdate = {'id': channel.id, 'position': index}
if parent_id is not MISSING and channel.id == self.id:
d.update(parent_id=parent_id, lock_permissions=lock_permissions)
payload.append(d)

10
discord/activity.py

@ -273,7 +273,7 @@ class Activity(BaseActivity):
def start(self) -> Optional[datetime.datetime]:
"""Optional[:class:`datetime.datetime`]: When the user started doing this activity in UTC, if applicable."""
try:
timestamp = self.timestamps['start'] / 1000
timestamp = self.timestamps['start'] / 1000 # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
return None
else:
@ -283,7 +283,7 @@ class Activity(BaseActivity):
def end(self) -> Optional[datetime.datetime]:
"""Optional[:class:`datetime.datetime`]: When the user will stop doing this activity in UTC, if applicable."""
try:
timestamp = self.timestamps['end'] / 1000
timestamp = self.timestamps['end'] / 1000 # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
return None
else:
@ -293,7 +293,7 @@ class Activity(BaseActivity):
def large_image_url(self) -> Optional[str]:
"""Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
try:
large_image = self.assets['large_image']
large_image = self.assets['large_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
return None
else:
@ -303,7 +303,7 @@ class Activity(BaseActivity):
def small_image_url(self) -> Optional[str]:
"""Optional[:class:`str`]: Returns a URL pointing to the small image asset of this activity, if applicable."""
try:
small_image = self.assets['small_image']
small_image = self.assets['small_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
return None
else:
@ -525,7 +525,7 @@ class Streaming(BaseActivity):
"""
try:
name = self.assets['large_image']
name = self.assets['large_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
return None
else:

8
discord/app_commands/commands.py

@ -903,7 +903,7 @@ class Command(Generic[GroupT, P, T]):
predicates = getattr(param.autocomplete, '__discord_app_commands_checks__', [])
if predicates:
try:
passed = await async_all(f(interaction) for f in predicates)
passed = await async_all(f(interaction) for f in predicates) # type: ignore
except Exception:
passed = False
@ -1014,7 +1014,7 @@ class Command(Generic[GroupT, P, T]):
if not predicates:
return True
return await async_all(f(interaction) for f in predicates)
return await async_all(f(interaction) for f in predicates) # type: ignore
def error(self, coro: Error[GroupT]) -> Error[GroupT]:
"""A decorator that registers a coroutine as a local error handler.
@ -1308,7 +1308,7 @@ class ContextMenu:
if not predicates:
return True
return await async_all(f(interaction) for f in predicates)
return await async_all(f(interaction) for f in predicates) # type: ignore
def _has_any_error_handlers(self) -> bool:
return self.on_error is not None
@ -1842,7 +1842,7 @@ class Group:
if len(params) != 2:
raise TypeError('The error handler must have 2 parameters.')
self.on_error = coro
self.on_error = coro # type: ignore
return coro
async def interaction_check(self, interaction: Interaction, /) -> bool:

2
discord/app_commands/transformers.py

@ -235,7 +235,7 @@ class Transformer(Generic[ClientT]):
pass
def __or__(self, rhs: Any) -> Any:
return Union[self, rhs] # type: ignore
return Union[self, rhs]
@property
def type(self) -> AppCommandOptionType:

2
discord/app_commands/tree.py

@ -859,7 +859,7 @@ class CommandTree(Generic[ClientT]):
if len(params) != 2:
raise TypeError('error handler must have 2 parameters')
self.on_error = coro
self.on_error = coro # type: ignore
return coro
def command(

6
discord/components.py

@ -196,12 +196,12 @@ class Button(Component):
self.label: Optional[str] = data.get('label')
self.emoji: Optional[PartialEmoji]
try:
self.emoji = PartialEmoji.from_dict(data['emoji'])
self.emoji = PartialEmoji.from_dict(data['emoji']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.emoji = None
try:
self.sku_id: Optional[int] = int(data['sku_id'])
self.sku_id: Optional[int] = int(data['sku_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.sku_id = None
@ -415,7 +415,7 @@ class SelectOption:
@classmethod
def from_dict(cls, data: SelectOptionPayload) -> SelectOption:
try:
emoji = PartialEmoji.from_dict(data['emoji'])
emoji = PartialEmoji.from_dict(data['emoji']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
emoji = None

12
discord/enums.py

@ -84,13 +84,13 @@ def _create_value_cls(name: str, comparable: bool):
# All the type ignores here are due to the type checker being unable to recognise
# Runtime type creation without exploding.
cls = namedtuple('_EnumValue_' + name, 'name value')
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>' # type: ignore
cls.__str__ = lambda self: f'{name}.{self.name}' # type: ignore
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>'
cls.__str__ = lambda self: f'{name}.{self.name}'
if comparable:
cls.__le__ = lambda self, other: isinstance(other, self.__class__) and self.value <= other.value # type: ignore
cls.__ge__ = lambda self, other: isinstance(other, self.__class__) and self.value >= other.value # type: ignore
cls.__lt__ = lambda self, other: isinstance(other, self.__class__) and self.value < other.value # type: ignore
cls.__gt__ = lambda self, other: isinstance(other, self.__class__) and self.value > other.value # type: ignore
cls.__le__ = lambda self, other: isinstance(other, self.__class__) and self.value <= other.value
cls.__ge__ = lambda self, other: isinstance(other, self.__class__) and self.value >= other.value
cls.__lt__ = lambda self, other: isinstance(other, self.__class__) and self.value < other.value
cls.__gt__ = lambda self, other: isinstance(other, self.__class__) and self.value > other.value
return cls

4
discord/ext/commands/bot.py

@ -172,7 +172,7 @@ class BotBase(GroupMixin[None]):
**options: Any,
) -> None:
super().__init__(intents=intents, **options)
self.command_prefix: PrefixType[BotT] = command_prefix
self.command_prefix: PrefixType[BotT] = command_prefix # type: ignore
self.extra_events: Dict[str, List[CoroFunc]] = {}
# Self doesn't have the ClientT bound, but since this is a mixin it technically does
self.__tree: app_commands.CommandTree[Self] = tree_cls(self) # type: ignore
@ -487,7 +487,7 @@ class BotBase(GroupMixin[None]):
if len(data) == 0:
return True
return await discord.utils.async_all(f(ctx) for f in data)
return await discord.utils.async_all(f(ctx) for f in data) # type: ignore
async def is_owner(self, user: User, /) -> bool:
"""|coro|

2
discord/ext/commands/context.py

@ -82,7 +82,7 @@ def is_cog(obj: Any) -> TypeGuard[Cog]:
return hasattr(obj, '__cog_commands__')
class DeferTyping:
class DeferTyping(Generic[BotT]):
def __init__(self, ctx: Context[BotT], *, ephemeral: bool):
self.ctx: Context[BotT] = ctx
self.ephemeral: bool = ephemeral

6
discord/ext/commands/converter.py

@ -1125,7 +1125,7 @@ class Greedy(List[T]):
args = getattr(converter, '__args__', ())
if discord.utils.PY_310 and converter.__class__ is types.UnionType: # type: ignore
converter = Union[args] # type: ignore
converter = Union[args]
origin = getattr(converter, '__origin__', None)
@ -1138,7 +1138,7 @@ class Greedy(List[T]):
if origin is Union and type(None) in args:
raise TypeError(f'Greedy[{converter!r}] is invalid.')
return cls(converter=converter)
return cls(converter=converter) # type: ignore
@property
def constructed_converter(self) -> Any:
@ -1325,7 +1325,7 @@ async def _actual_conversion(ctx: Context[BotT], converter: Any, argument: str,
else:
return await converter().convert(ctx, argument)
elif isinstance(converter, Converter):
return await converter.convert(ctx, argument) # type: ignore
return await converter.convert(ctx, argument)
except CommandError:
raise
except Exception as exc:

2
discord/ext/commands/core.py

@ -1285,7 +1285,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
# since we have no checks, then we just return True.
return True
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
return await discord.utils.async_all(predicate(ctx) for predicate in predicates) # type: ignore
finally:
ctx.command = original

7
discord/ext/commands/errors.py

@ -24,18 +24,19 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union, Generic
from discord.errors import ClientException, DiscordException
from discord.utils import _human_join
from ._types import BotT
if TYPE_CHECKING:
from discord.abc import GuildChannel
from discord.threads import Thread
from discord.types.snowflake import Snowflake, SnowflakeList
from discord.app_commands import AppCommandError
from ._types import BotT
from .context import Context
from .converter import Converter
from .cooldowns import BucketType, Cooldown
@ -235,7 +236,7 @@ class CheckFailure(CommandError):
pass
class CheckAnyFailure(CheckFailure):
class CheckAnyFailure(Generic[BotT], CheckFailure):
"""Exception raised when all predicates in :func:`check_any` fail.
This inherits from :exc:`CheckFailure`.

2
discord/ext/commands/flags.py

@ -443,7 +443,7 @@ async def convert_flag(ctx: Context[BotT], argument: str, flag: Flag, annotation
return await convert_flag(ctx, argument, flag, annotation)
elif origin is Union and type(None) in annotation.__args__:
# typing.Optional[x]
annotation = Union[tuple(arg for arg in annotation.__args__ if arg is not type(None))] # type: ignore
annotation = Union[tuple(arg for arg in annotation.__args__ if arg is not type(None))]
return await run_converters(ctx, annotation, argument, param)
elif origin is dict:
# typing.Dict[K, V] -> typing.Tuple[K, V]

13
discord/ext/commands/hybrid.py

@ -203,9 +203,9 @@ def replace_parameter(
# Fallback to see if the behaviour needs changing
origin = getattr(converter, '__origin__', None)
args = getattr(converter, '__args__', [])
if isinstance(converter, Range):
if isinstance(converter, Range): # type: ignore # Range is not an Annotation at runtime
r = converter
param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max])
param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max]) # type: ignore
elif isinstance(converter, Greedy):
# Greedy is "optional" in ext.commands
# However, in here, it probably makes sense to make it required.
@ -257,7 +257,7 @@ def replace_parameter(
inner = args[0]
is_inner_transformer = is_transformer(inner)
if is_converter(inner) and not is_inner_transformer:
param = param.replace(annotation=Optional[ConverterTransformer(inner, original)]) # type: ignore
param = param.replace(annotation=Optional[ConverterTransformer(inner, original)])
else:
raise
elif origin:
@ -424,10 +424,10 @@ class HybridAppCommand(discord.app_commands.Command[CogT, P, T]):
if not ret:
return False
if self.checks and not await async_all(f(interaction) for f in self.checks):
if self.checks and not await async_all(f(interaction) for f in self.checks): # type: ignore
return False
if self.wrapped.checks and not await async_all(f(ctx) for f in self.wrapped.checks):
if self.wrapped.checks and not await async_all(f(ctx) for f in self.wrapped.checks): # type: ignore
return False
return True
@ -915,7 +915,8 @@ def hybrid_command(
def decorator(func: CommandCallback[CogT, ContextT, P, T]) -> HybridCommand[CogT, P, T]:
if isinstance(func, Command):
raise TypeError('Callback is already a command.')
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs)
# Pyright does not allow Command[Any] to be assigned to Command[CogT] despite it being okay here
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) # type: ignore
return decorator

4
discord/gateway.py

@ -831,7 +831,7 @@ class DiscordVoiceWebSocket:
self._close_code: Optional[int] = None
self.secret_key: Optional[List[int]] = None
if hook:
self._hook = hook
self._hook = hook # type: ignore
async def _hook(self, *args: Any) -> None:
pass
@ -893,7 +893,7 @@ class DiscordVoiceWebSocket:
return ws
async def select_protocol(self, ip: str, port: int, mode: int) -> None:
async def select_protocol(self, ip: str, port: int, mode: str) -> None:
payload = {
'op': self.SELECT_PROTOCOL,
'd': {

5
discord/guild.py

@ -551,7 +551,8 @@ class Guild(Hashable):
member = self.get_member(user_id)
if member is None:
try:
member = Member(data=data['member'], state=self._state, guild=self)
member_data = data['member'] # pyright: ignore[reportTypedDictNotRequiredAccess]
member = Member(data=member_data, state=self._state, guild=self)
except KeyError:
member = None
@ -573,7 +574,7 @@ class Guild(Hashable):
def _from_data(self, guild: GuildPayload) -> None:
try:
self._member_count = guild['member_count']
self._member_count = guild['member_count'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass

5
discord/interactions.py

@ -219,14 +219,15 @@ class Interaction(Generic[ClientT]):
int(k): int(v) for k, v in data.get('authorizing_integration_owners', {}).items()
}
try:
self.context = AppCommandContext._from_value([data['context']])
value = data['context'] # pyright: ignore[reportTypedDictNotRequiredAccess]
self.context = AppCommandContext._from_value([value])
except KeyError:
self.context = AppCommandContext()
self.locale: Locale = try_enum(Locale, data.get('locale', 'en-US'))
self.guild_locale: Optional[Locale]
try:
self.guild_locale = try_enum(Locale, data['guild_locale'])
self.guild_locale = try_enum(Locale, data['guild_locale']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_locale = None

2
discord/invite.py

@ -437,7 +437,7 @@ class Invite(Hashable):
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
guild: Optional[Union[Guild, PartialInviteGuild]]
try:
guild_data = data['guild']
guild_data = data['guild'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
# If we're here, then this is a group DM
guild = None

6
discord/member.py

@ -326,7 +326,7 @@ class Member(discord.abc.Messageable, _UserTag):
self._flags: int = data['flags']
self._avatar_decoration_data: Optional[AvatarDecorationData] = data.get('avatar_decoration_data')
try:
self._permissions = int(data['permissions'])
self._permissions = int(data['permissions']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self._permissions = None
@ -418,12 +418,12 @@ class Member(discord.abc.Messageable, _UserTag):
# the nickname change is optional,
# if it isn't in the payload then it didn't change
try:
self.nick = data['nick']
self.nick = data['nick'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
try:
self.pending = data['pending']
self.pending = data['pending'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass

23
discord/message.py

@ -773,7 +773,7 @@ class MessageInteraction(Hashable):
self.user: Union[User, Member] = MISSING
try:
payload = data['member']
payload = data['member'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.user = state.create_user(data['user'])
else:
@ -2200,7 +2200,8 @@ class Message(PartialMessage, Hashable):
self.poll: Optional[Poll] = None
try:
self.poll = Poll._from_data(data=data['poll'], message=self, state=state)
poll = data['poll'] # pyright: ignore[reportTypedDictNotRequiredAccess]
self.poll = Poll._from_data(data=poll, message=self, state=state)
except KeyError:
pass
@ -2214,7 +2215,7 @@ class Message(PartialMessage, Hashable):
if self.guild is not None:
try:
thread = data['thread']
thread = data['thread'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2229,7 +2230,7 @@ class Message(PartialMessage, Hashable):
# deprecated
try:
interaction = data['interaction']
interaction = data['interaction'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2237,20 +2238,20 @@ class Message(PartialMessage, Hashable):
self.interaction_metadata: Optional[MessageInteractionMetadata] = None
try:
interaction_metadata = data['interaction_metadata']
interaction_metadata = data['interaction_metadata'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
self.interaction_metadata = MessageInteractionMetadata(state=state, guild=self.guild, data=interaction_metadata)
try:
ref = data['message_reference']
ref = data['message_reference'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.reference = None
else:
self.reference = ref = MessageReference.with_state(state, ref)
try:
resolved = data['referenced_message']
resolved = data['referenced_message'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2277,7 +2278,7 @@ class Message(PartialMessage, Hashable):
self.application: Optional[MessageApplication] = None
try:
application = data['application']
application = data['application'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2285,7 +2286,7 @@ class Message(PartialMessage, Hashable):
self.role_subscription: Optional[RoleSubscriptionInfo] = None
try:
role_subscription = data['role_subscription_data']
role_subscription = data['role_subscription_data'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2293,7 +2294,7 @@ class Message(PartialMessage, Hashable):
self.purchase_notification: Optional[PurchaseNotification] = None
try:
purchase_notification = data['purchase_notification']
purchase_notification = data['purchase_notification'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
pass
else:
@ -2301,7 +2302,7 @@ class Message(PartialMessage, Hashable):
for handler in ('author', 'member', 'mentions', 'mention_roles', 'components', 'call'):
try:
getattr(self, f'_handle_{handler}')(data[handler])
getattr(self, f'_handle_{handler}')(data[handler]) # type: ignore
except KeyError:
continue

14
discord/raw_models.py

@ -104,7 +104,7 @@ class RawMessageDeleteEvent(_RawReprMixin):
self.channel_id: int = int(data['channel_id'])
self.cached_message: Optional[Message] = None
try:
self.guild_id: Optional[int] = int(data['guild_id'])
self.guild_id: Optional[int] = int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_id: Optional[int] = None
@ -132,7 +132,7 @@ class RawBulkMessageDeleteEvent(_RawReprMixin):
self.cached_messages: List[Message] = []
try:
self.guild_id: Optional[int] = int(data['guild_id'])
self.guild_id: Optional[int] = int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_id: Optional[int] = None
@ -248,7 +248,7 @@ class RawReactionActionEvent(_RawReprMixin):
self.type: ReactionType = try_enum(ReactionType, data['type'])
try:
self.guild_id: Optional[int] = int(data['guild_id'])
self.guild_id: Optional[int] = int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_id: Optional[int] = None
@ -281,7 +281,7 @@ class RawReactionClearEvent(_RawReprMixin):
self.channel_id: int = int(data['channel_id'])
try:
self.guild_id: Optional[int] = int(data['guild_id'])
self.guild_id: Optional[int] = int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_id: Optional[int] = None
@ -311,7 +311,7 @@ class RawReactionClearEmojiEvent(_RawReprMixin):
self.channel_id: int = int(data['channel_id'])
try:
self.guild_id: Optional[int] = int(data['guild_id'])
self.guild_id: Optional[int] = int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.guild_id: Optional[int] = None
@ -338,7 +338,9 @@ class RawIntegrationDeleteEvent(_RawReprMixin):
self.guild_id: int = int(data['guild_id'])
try:
self.application_id: Optional[int] = int(data['application_id'])
self.application_id: Optional[int] = int(
data['application_id'] # pyright: ignore[reportTypedDictNotRequiredAccess]
)
except KeyError:
self.application_id: Optional[int] = None

2
discord/role.py

@ -286,7 +286,7 @@ class Role(Hashable):
self._flags: int = data.get('flags', 0)
try:
self.tags = RoleTags(data['tags'])
self.tags = RoleTags(data['tags']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.tags = None

8
discord/state.py

@ -540,7 +540,7 @@ class ConnectionState(Generic[ClientT]):
) -> Tuple[Union[Channel, Thread], Optional[Guild]]:
channel_id = int(data['channel_id'])
try:
guild_id = guild_id or int(data['guild_id'])
guild_id = guild_id or int(data['guild_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
guild = self._get_guild(guild_id)
except KeyError:
channel = DMChannel._from_message(self, channel_id)
@ -736,7 +736,7 @@ class ConnectionState(Generic[ClientT]):
if 'components' in data:
try:
entity_id = int(data['interaction']['id'])
entity_id = int(data['interaction']['id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
except (KeyError, ValueError):
entity_id = raw.message_id
@ -935,7 +935,7 @@ class ConnectionState(Generic[ClientT]):
def parse_channel_pins_update(self, data: gw.ChannelPinsUpdateEvent) -> None:
channel_id = int(data['channel_id'])
try:
guild = self._get_guild(int(data['guild_id']))
guild = self._get_guild(int(data['guild_id'])) # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
guild = None
channel = self._get_private_channel(channel_id)
@ -1017,7 +1017,7 @@ class ConnectionState(Generic[ClientT]):
return
try:
channel_ids = {int(i) for i in data['channel_ids']}
channel_ids = {int(i) for i in data['channel_ids']} # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
# If not provided, then the entire guild is being synced
# So all previous thread data should be overwritten

2
discord/threads.py

@ -192,7 +192,7 @@ class Thread(Messageable, Hashable):
self.me: Optional[ThreadMember]
try:
member = data['member']
member = data['member'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
self.me = None
else:

4
discord/types/guild.py

@ -179,8 +179,8 @@ class GuildMFALevel(TypedDict):
class ChannelPositionUpdate(TypedDict):
id: Snowflake
position: Optional[int]
lock_permissions: Optional[bool]
parent_id: Optional[Snowflake]
lock_permissions: NotRequired[Optional[bool]]
parent_id: NotRequired[Optional[Snowflake]]
class _RolePositionRequired(TypedDict):

5
discord/ui/select.py

@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
from typing import (
Any,
@ -330,7 +331,9 @@ class BaseSelect(Item[V]):
values = selected_values.get({})
payload: List[PossibleValue]
try:
resolved = Namespace._get_resolved_items(interaction, data['resolved'])
resolved = Namespace._get_resolved_items(
interaction, data['resolved'] # pyright: ignore[reportTypedDictNotRequiredAccess]
)
payload = list(resolved.values())
except KeyError:
payload = data.get("values", []) # type: ignore

2
discord/ui/view.py

@ -177,7 +177,7 @@ class View:
children = []
for func in self.__view_children_items__:
item: Item = func.__discord_ui_model_type__(**func.__discord_ui_model_kwargs__)
item.callback = _ViewCallback(func, self, item)
item.callback = _ViewCallback(func, self, item) # type: ignore
item._view = self
setattr(self, func.__name__, item)
children.append(item)

6
discord/utils.py

@ -714,13 +714,13 @@ async def maybe_coroutine(f: MaybeAwaitableFunc[P, T], *args: P.args, **kwargs:
if _isawaitable(value):
return await value
else:
return value # type: ignore
return value
async def async_all(
gen: Iterable[Union[T, Awaitable[T]]],
*,
check: Callable[[Union[T, Awaitable[T]]], TypeGuard[Awaitable[T]]] = _isawaitable,
check: Callable[[Union[T, Awaitable[T]]], TypeGuard[Awaitable[T]]] = _isawaitable, # type: ignore
) -> bool:
for elem in gen:
if check(elem):
@ -1121,7 +1121,7 @@ def flatten_literal_params(parameters: Iterable[Any]) -> Tuple[Any, ...]:
literal_cls = type(Literal[0])
for p in parameters:
if isinstance(p, literal_cls):
params.extend(p.__args__)
params.extend(p.__args__) # type: ignore
else:
params.append(p)
return tuple(params)

2
discord/widget.py

@ -184,7 +184,7 @@ class WidgetMember(BaseUser):
self.suppress: Optional[bool] = data.get('suppress', False)
try:
game = data['game']
game = data['game'] # pyright: ignore[reportTypedDictNotRequiredAccess]
except KeyError:
activity = None
else:

Loading…
Cancel
Save