From 2a880be6b8f6273753999e0bd466d94d8d07e3c4 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 2 Jul 2023 08:26:27 +1000 Subject: [PATCH] Update pyright version --- .github/workflows/lint.yml | 2 +- discord/abc.py | 2 ++ discord/channel.py | 2 +- discord/ext/commands/core.py | 6 +++--- discord/ext/commands/flags.py | 4 ++-- discord/ext/commands/parameters.py | 2 +- discord/flags.py | 18 ++++++++++++++++-- discord/guild.py | 11 +++++++---- discord/http.py | 4 ++-- discord/invite.py | 6 ++++++ 10 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 61fc9d151..b7bd8abb1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -34,7 +34,7 @@ jobs: - name: Run Pyright uses: jakebailey/pyright-action@v1 with: - version: '1.1.289' + version: '1.1.316' warnings: false no-comments: false diff --git a/discord/abc.py b/discord/abc.py index 85b9f95f1..9f30fbb68 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1511,6 +1511,8 @@ class GuildChannel: :class:`~discord.Invite` The invite that was created. """ + if target_type is InviteTarget.unknown: + target_type = None data = await self._state.http.create_invite( self.id, diff --git a/discord/channel.py b/discord/channel.py index 900d3eb0a..d6ad0cc6c 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -833,7 +833,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): self.id, name=name, auto_archive_duration=auto_archive_duration or self.default_auto_archive_duration, - type=type.value, + type=type.value, # type: ignore # we're assuming that the user is passing a valid variant reason=reason, invitable=invitable, rate_limit_per_user=slowmode_delay, diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index e0c91f4a8..851a22e8d 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -773,7 +773,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): command = self # command.parent is type-hinted as GroupMixin some attributes are resolved via MRO while command.parent is not None: # type: ignore - command = command.parent # type: ignore + command = command.parent entries.append(command.name) # type: ignore return ' '.join(reversed(entries)) @@ -791,7 +791,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): entries = [] command = self while command.parent is not None: # type: ignore - command = command.parent # type: ignore + command = command.parent entries.append(command) return entries @@ -2001,7 +2001,7 @@ def check_any(*checks: Check[ContextT]) -> Check[ContextT]: # if we're here, all checks failed raise CheckAnyFailure(unwrapped, errors) - return check(predicate) # type: ignore + return check(predicate) def has_role(item: Union[int, str], /) -> Check[Any]: diff --git a/discord/ext/commands/flags.py b/discord/ext/commands/flags.py index 6f7f67e60..35616c5ea 100644 --- a/discord/ext/commands/flags.py +++ b/discord/ext/commands/flags.py @@ -465,7 +465,7 @@ class FlagConverter(metaclass=FlagsMeta): for flag in flags.values(): if callable(flag.default): # Type checker does not understand that flag.default is a Callable - default = await maybe_coroutine(flag.default, ctx) # type: ignore + default = await maybe_coroutine(flag.default, ctx) setattr(self, flag.attribute, default) else: setattr(self, flag.attribute, flag.default) @@ -580,7 +580,7 @@ class FlagConverter(metaclass=FlagsMeta): else: if callable(flag.default): # Type checker does not understand flag.default is a Callable - default = await maybe_coroutine(flag.default, ctx) # type: ignore + default = await maybe_coroutine(flag.default, ctx) setattr(self, flag.attribute, default) else: setattr(self, flag.attribute, flag.default) diff --git a/discord/ext/commands/parameters.py b/discord/ext/commands/parameters.py index d3302f5a3..181653bdc 100644 --- a/discord/ext/commands/parameters.py +++ b/discord/ext/commands/parameters.py @@ -197,7 +197,7 @@ class Parameter(inspect.Parameter): """ # pre-condition: required is False if callable(self.default): - return await maybe_coroutine(self.default, ctx) # type: ignore + return await maybe_coroutine(self.default, ctx) return self.default diff --git a/discord/flags.py b/discord/flags.py index 5cd929192..3b6c1a3dc 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -26,7 +26,21 @@ from __future__ import annotations from functools import reduce from operator import or_ -from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Iterator, List, Optional, Tuple, Type, TypeVar, overload +from typing import ( + TYPE_CHECKING, + Any, + Callable, + ClassVar, + Dict, + Iterator, + List, + Optional, + Sequence, + Tuple, + Type, + TypeVar, + overload, +) from .enums import UserFlags @@ -200,7 +214,7 @@ class BaseFlags: class ArrayFlags(BaseFlags): @classmethod - def _from_value(cls: Type[Self], value: List[int]) -> Self: + def _from_value(cls: Type[Self], value: Sequence[int]) -> Self: self = cls.__new__(cls) # This is a micro-optimization given the frequency this object can be created. # (1).__lshift__ is used in place of lambda x: 1 << x diff --git a/discord/guild.py b/discord/guild.py index 727abd491..3c2e1b604 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -133,6 +133,7 @@ if TYPE_CHECKING: from .types.message import MessageSearchAuthorType, MessageSearchHasType from .types.snowflake import SnowflakeList, Snowflake as _Snowflake from .types.widget import EditWidgetSettings + from .types.audit_log import AuditLogEvent from .types.oauth2 import OAuth2Guild as OAuth2GuildPayload from .message import EmojiInputType, Message from .read_state import ReadState @@ -4231,7 +4232,7 @@ class Guild(Hashable): async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[int]): before_id = before.id if before else None data = await self._state.http.get_audit_logs( - self.id, limit=retrieve, user_id=user_id, action_type=action, before=before_id + self.id, limit=retrieve, user_id=user_id, action_type=action_type, before=before_id ) entries = data.get('audit_log_entries', []) @@ -4247,7 +4248,7 @@ class Guild(Hashable): async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[int]): after_id = after.id if after else None data = await self._state.http.get_audit_logs( - self.id, limit=retrieve, user_id=user_id, action_type=action, after=after_id + self.id, limit=retrieve, user_id=user_id, action_type=action_type, after=after_id ) entries = data.get('audit_log_entries', []) @@ -4265,8 +4266,10 @@ class Guild(Hashable): else: user_id = None - if action: - action = action.value + if action is not MISSING: + action_type: Optional[AuditLogEvent] = action.value + else: + action_type = None if isinstance(before, datetime): before = Object(id=utils.time_snowflake(before, high=False)) diff --git a/discord/http.py b/discord/http.py index bc41248af..641e18d19 100644 --- a/discord/http.py +++ b/discord/http.py @@ -80,7 +80,7 @@ if TYPE_CHECKING: from .mentions import AllowedMentions from .message import Attachment, Message from .flags import MessageFlags - from .enums import AuditLogAction, ChannelType, InteractionType + from .enums import ChannelType, InteractionType from .embeds import Embed from .types import ( @@ -2200,7 +2200,7 @@ class HTTPClient: before: Optional[Snowflake] = None, after: Optional[Snowflake] = None, user_id: Optional[Snowflake] = None, - action_type: Optional[AuditLogAction] = None, + action_type: Optional[audit_log.AuditLogEvent] = None, ) -> Response[audit_log.AuditLog]: r = Route('GET', '/guilds/{guild_id}/audit-logs', guild_id=guild_id) params: Dict[str, Any] = {'limit': limit} diff --git a/discord/invite.py b/discord/invite.py index e582e4a3c..b3099b5bf 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -58,6 +58,12 @@ if TYPE_CHECKING: Invite as InvitePayload, InviteGuild as InviteGuildPayload, ) + from .types.channel import ( + PartialChannel as InviteChannelPayload, + ) + from .state import ConnectionState + from .guild import Guild + from .abc import GuildChannel from .user import User InviteGuildType = Union[Guild, 'PartialInviteGuild', Object]