From 30e7a2e937ea55ffa21658aa8d11d43aa4ae9854 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 21 Feb 2022 23:31:18 -0500 Subject: [PATCH] Fix a few more type errors --- discord/http.py | 4 ++-- discord/integrations.py | 1 + discord/interactions.py | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/discord/http.py b/discord/http.py index 895de9b3b..c5a9f5c9e 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1758,7 +1758,7 @@ class HTTPClient: 'description', 'options', ) - payload = {k: v for k, v in payload.items() if k in valid_keys} # type: ignore + payload = {k: v for k, v in payload.items() if k in valid_keys} r = Route( 'PATCH', '/applications/{application_id}/commands/{command_id}', @@ -1834,7 +1834,7 @@ class HTTPClient: 'description', 'options', ) - payload = {k: v for k, v in payload.items() if k in valid_keys} # type: ignore + payload = {k: v for k, v in payload.items() if k in valid_keys} r = Route( 'PATCH', '/applications/{application_id}/guilds/{guild_id}/commands/{command_id}', diff --git a/discord/integrations.py b/discord/integrations.py index 23d029303..e877fdda1 100644 --- a/discord/integrations.py +++ b/discord/integrations.py @@ -215,6 +215,7 @@ class StreamIntegration(Integration): @property def role(self) -> Optional[Role]: """Optional[:class:`Role`] The role which the integration uses for subscribers.""" + # The key is `int` but `int | None` will return `None` anyway. return self.guild.get_role(self._role_id) # type: ignore async def edit( diff --git a/discord/interactions.py b/discord/interactions.py index 7e3b0f210..03fddb88d 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -124,7 +124,7 @@ class Interaction: def __init__(self, *, data: InteractionPayload, state: ConnectionState): self._state: ConnectionState = state - self._session: ClientSession = state.http._HTTPClient__session + self._session: ClientSession = state.http._HTTPClient__session # type: ignore - Mangled attribute for __session self._original_message: Optional[InteractionMessage] = None self._from_data(data) @@ -140,6 +140,7 @@ class Interaction: self.message: Optional[Message] try: + # The channel and message payloads are mismatched yet handled properly at runtime self.message = Message(state=self._state, channel=self.channel, data=data['message']) # type: ignore except KeyError: self.message = None @@ -151,15 +152,16 @@ class Interaction: if self.guild_id: guild = self.guild or Object(id=self.guild_id) try: - member = data['member'] # type: ignore + member = data['member'] # type: ignore - The key is optional and handled except KeyError: pass else: + # The fallback to Object for guild causes a type check error but is explicitly allowed here self.user = Member(state=self._state, guild=guild, data=member) # type: ignore self._permissions = int(member.get('permissions', 0)) else: try: - self.user = User(state=self._state, data=data['user']) + self.user = User(state=self._state, data=data['user']) # type: ignore - The key is optional and handled except KeyError: pass @@ -250,6 +252,7 @@ class Interaction: session=self._session, ) state = _InteractionMessageState(self, self._state) + # The state and channel parameters are mocked here message = InteractionMessage(state=state, channel=channel, data=data) # type: ignore self._original_message = message return message