From 4e03b170ef0c54167d679ac6cd077a7ba984e026 Mon Sep 17 00:00:00 2001 From: Josh <8677174+bijij@users.noreply.github.com> Date: Wed, 21 Feb 2024 05:36:02 +1100 Subject: [PATCH] Update pyright version --- .github/workflows/lint.yml | 2 +- discord/app_commands/checks.py | 2 +- discord/app_commands/transformers.py | 8 ++++---- discord/asset.py | 6 +++--- discord/automod.py | 2 +- discord/client.py | 2 +- discord/colour.py | 2 +- discord/enums.py | 12 ++++++++---- discord/ext/commands/cog.py | 4 ++-- discord/ext/commands/converter.py | 2 +- discord/ext/commands/core.py | 6 +++--- discord/ext/commands/flags.py | 2 +- discord/ext/commands/hybrid.py | 2 +- discord/file.py | 2 +- discord/ui/select.py | 16 ++++++++-------- discord/utils.py | 2 +- discord/welcome_screen.py | 2 +- 17 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b233a5deff09..9e70f794faab 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -38,7 +38,7 @@ jobs: - name: Run Pyright uses: jakebailey/pyright-action@v1 with: - version: '1.1.316' + version: '1.1.351' warnings: false no-comments: ${{ matrix.python-version != '3.x' }} diff --git a/discord/app_commands/checks.py b/discord/app_commands/checks.py index f6c09481d549..5c17b951c294 100644 --- a/discord/app_commands/checks.py +++ b/discord/app_commands/checks.py @@ -186,7 +186,7 @@ def copy(self) -> Self: :class:`Cooldown` A new instance of this cooldown. """ - return Cooldown(self.rate, self.per) + return self.__class__(self.rate, self.per) def __repr__(self) -> str: return f'' diff --git a/discord/app_commands/transformers.py b/discord/app_commands/transformers.py index 59b3af758310..d012c52b98af 100644 --- a/discord/app_commands/transformers.py +++ b/discord/app_commands/transformers.py @@ -638,7 +638,7 @@ def __init__(self, *channel_types: Type[Any]) -> None: except KeyError: raise TypeError('Union type of channels must be entirely made up of channels') from None - self._types: Tuple[Type[Any]] = channel_types + self._types: Tuple[Type[Any], ...] = channel_types self._channel_types: List[ChannelType] = types self._display_name = display_name @@ -780,11 +780,11 @@ def get_supported_annotation( # Check if there's an origin origin = getattr(annotation, '__origin__', None) if origin is Literal: - args = annotation.__args__ # type: ignore + args = annotation.__args__ return (LiteralTransformer(args), MISSING, True) if origin is Choice: - arg = annotation.__args__[0] # type: ignore + arg = annotation.__args__[0] return (ChoiceTransformer(arg), MISSING, True) if origin is not Union: @@ -792,7 +792,7 @@ def get_supported_annotation( raise TypeError(f'unsupported type annotation {annotation!r}') default = MISSING - args = annotation.__args__ # type: ignore + args = annotation.__args__ if args[-1] is _none: if len(args) == 2: underlying = args[0] diff --git a/discord/asset.py b/discord/asset.py index d08635632015..7b9b711334a3 100644 --- a/discord/asset.py +++ b/discord/asset.py @@ -429,7 +429,7 @@ def replace( url = url.with_query(url.raw_query_string) url = str(url) - return Asset(state=self._state, url=url, key=self._key, animated=self._animated) + return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated) def with_size(self, size: int, /) -> Self: """Returns a new asset with the specified size. @@ -457,7 +457,7 @@ def with_size(self, size: int, /) -> Self: raise ValueError('size must be a power of 2 between 16 and 4096') url = str(yarl.URL(self._url).with_query(size=size)) - return Asset(state=self._state, url=url, key=self._key, animated=self._animated) + return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated) def with_format(self, format: ValidAssetFormatTypes, /) -> Self: """Returns a new asset with the specified format. @@ -492,7 +492,7 @@ def with_format(self, format: ValidAssetFormatTypes, /) -> Self: url = yarl.URL(self._url) path, _ = os.path.splitext(url.path) url = str(url.with_path(f'{path}.{format}').with_query(url.raw_query_string)) - return Asset(state=self._state, url=url, key=self._key, animated=self._animated) + return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated) def with_static_format(self, format: ValidStaticFormatTypes, /) -> Self: """Returns a new asset with the specified static format. diff --git a/discord/automod.py b/discord/automod.py index b20f9016a12a..eabf42806be3 100644 --- a/discord/automod.py +++ b/discord/automod.py @@ -541,7 +541,7 @@ async def edit( **payload, ) - return AutoModRule(data=data, guild=self.guild, state=self._state) + return self.__class__(data=data, guild=self.guild, state=self._state) async def delete(self, *, reason: str = MISSING) -> None: """|coro| diff --git a/discord/client.py b/discord/client.py index ccafc073d1ea..b3243ef93bd4 100644 --- a/discord/client.py +++ b/discord/client.py @@ -315,7 +315,7 @@ async def __aexit__( def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket: return self.ws - def _get_state(self, **options: Any) -> ConnectionState: + def _get_state(self, **options: Any) -> ConnectionState[Self]: return ConnectionState(dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, **options) def _handle_ready(self) -> None: diff --git a/discord/colour.py b/discord/colour.py index 5772b145d426..7e3a37132a11 100644 --- a/discord/colour.py +++ b/discord/colour.py @@ -175,7 +175,7 @@ def from_hsv(cls, h: float, s: float, v: float) -> Self: return cls.from_rgb(*(int(x * 255) for x in rgb)) @classmethod - def from_str(cls, value: str) -> Self: + def from_str(cls, value: str) -> Colour: """Constructs a :class:`Colour` from a string. The following formats are accepted: diff --git a/discord/enums.py b/discord/enums.py index ed498b8be190..0c6f93fdf2ec 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -75,9 +75,6 @@ 'EntitlementOwnerType', ) -if TYPE_CHECKING: - from typing_extensions import Self - def _create_value_cls(name: str, comparable: bool): # All the type ignores here are due to the type checker being unable to recognise @@ -104,7 +101,14 @@ class EnumMeta(type): _enum_member_map_: ClassVar[Dict[str, Any]] _enum_value_map_: ClassVar[Dict[Any, Any]] - def __new__(cls, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any], *, comparable: bool = False) -> Self: + def __new__( + cls, + name: str, + bases: Tuple[type, ...], + attrs: Dict[str, Any], + *, + comparable: bool = False, + ) -> EnumMeta: value_mapping = {} member_mapping = {} member_names = [] diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index 1ffe25c702bb..54842c2599a9 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -169,7 +169,7 @@ async def bar(self, ctx): __cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]] __cog_listeners__: List[Tuple[str, str]] - def __new__(cls, *args: Any, **kwargs: Any) -> Self: + def __new__(cls, *args: Any, **kwargs: Any) -> CogMeta: name, bases, attrs = args if any(issubclass(base, app_commands.Group) for base in bases): raise TypeError( @@ -366,7 +366,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Self: child.wrapped = lookup[child.qualified_name] # type: ignore if self.__cog_app_commands_group__: - children.append(app_command) # type: ignore # Somehow it thinks it can be None here + children.append(app_command) if Cog._get_overridden_method(self.cog_app_command_error) is not None: error_handler = self.cog_app_command_error diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 7255f171540b..41e0f6c4a5b5 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1185,7 +1185,7 @@ def _convert_to_bool(argument: str) -> bool: raise BadBoolArgument(lowered) -_GenericAlias = type(List[T]) +_GenericAlias = type(List[T]) # type: ignore def is_generic_type(tp: Any, *, _GenericAlias: type = _GenericAlias) -> bool: diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index efd7b09d29fc..1c682a957725 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -461,7 +461,7 @@ def __init__( # bandaid for the fact that sometimes parent can be the bot instance parent: Optional[GroupMixin[Any]] = kwargs.get('parent') - self.parent: Optional[GroupMixin[Any]] = parent if isinstance(parent, _BaseCommand) else None # type: ignore # Does not recognise mixin usage + self.parent: Optional[GroupMixin[Any]] = parent if isinstance(parent, _BaseCommand) else None self._before_invoke: Optional[Hook] = None try: @@ -776,7 +776,7 @@ def full_parent_name(self) -> str: 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 + command = command.parent # type: ignore entries.append(command.name) # type: ignore return ' '.join(reversed(entries)) @@ -794,7 +794,7 @@ def parents(self) -> List[Group[Any, ..., Any]]: entries = [] command = self while command.parent is not None: # type: ignore - command = command.parent + command = command.parent # type: ignore entries.append(command) return entries diff --git a/discord/ext/commands/flags.py b/discord/ext/commands/flags.py index 280b652573ef..dee00fa7e5c6 100644 --- a/discord/ext/commands/flags.py +++ b/discord/ext/commands/flags.py @@ -280,7 +280,7 @@ def __new__( case_insensitive: bool = MISSING, delimiter: str = MISSING, prefix: str = MISSING, - ) -> Self: + ) -> FlagsMeta: attrs['__commands_is_flag__'] = True try: diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index a8775474dc9a..c9797e734eeb 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -902,7 +902,7 @@ 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) # type: ignore # ??? + return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) return decorator diff --git a/discord/file.py b/discord/file.py index 504d86b73a80..7e4df415b241 100644 --- a/discord/file.py +++ b/discord/file.py @@ -111,7 +111,7 @@ def __init__( else: filename = getattr(fp, 'name', 'untitled') - self._filename, filename_spoiler = _strip_spoiler(filename) + self._filename, filename_spoiler = _strip_spoiler(filename) # type: ignore # pyright doesn't understand the above getattr if spoiler is MISSING: spoiler = filename_spoiler diff --git a/discord/ui/select.py b/discord/ui/select.py index 294a539dd489..b7a8e694cf1c 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -69,7 +69,7 @@ ) if TYPE_CHECKING: - from typing_extensions import TypeAlias, Self, TypeGuard + from typing_extensions import TypeAlias, TypeGuard from .view import View from ..types.components import SelectMenu as SelectMenuPayload @@ -342,7 +342,7 @@ def is_dispatchable(self) -> bool: return True @classmethod - def from_component(cls, component: SelectMenu) -> Self: + def from_component(cls, component: SelectMenu) -> BaseSelect[V]: type_to_cls: Dict[ComponentType, Type[BaseSelect[Any]]] = { ComponentType.string_select: Select, ComponentType.user_select: UserSelect, @@ -887,7 +887,7 @@ def default_values(self, value: Sequence[ValidDefaultValues]) -> None: @overload def select( *, - cls: Type[SelectT] = Select[V], + cls: Type[SelectT] = Select[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = ..., placeholder: Optional[str] = ..., @@ -903,7 +903,7 @@ def select( @overload def select( *, - cls: Type[UserSelectT] = UserSelect[V], + cls: Type[UserSelectT] = UserSelect[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = ..., placeholder: Optional[str] = ..., @@ -920,7 +920,7 @@ def select( @overload def select( *, - cls: Type[RoleSelectT] = RoleSelect[V], + cls: Type[RoleSelectT] = RoleSelect[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = ..., placeholder: Optional[str] = ..., @@ -937,7 +937,7 @@ def select( @overload def select( *, - cls: Type[ChannelSelectT] = ChannelSelect[V], + cls: Type[ChannelSelectT] = ChannelSelect[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = ..., placeholder: Optional[str] = ..., @@ -954,7 +954,7 @@ def select( @overload def select( *, - cls: Type[MentionableSelectT] = MentionableSelect[V], + cls: Type[MentionableSelectT] = MentionableSelect[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = MISSING, placeholder: Optional[str] = ..., @@ -970,7 +970,7 @@ def select( def select( *, - cls: Type[BaseSelectT] = Select[V], + cls: Type[BaseSelectT] = Select[Any], options: List[SelectOption] = MISSING, channel_types: List[ChannelType] = MISSING, placeholder: Optional[str] = None, diff --git a/discord/utils.py b/discord/utils.py index 33a4020a2504..3509bf3ab19e 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -721,7 +721,7 @@ async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: Optional[fl def get_slots(cls: Type[Any]) -> Iterator[str]: for mro in reversed(cls.__mro__): try: - yield from mro.__slots__ # type: ignore + yield from mro.__slots__ except AttributeError: continue diff --git a/discord/welcome_screen.py b/discord/welcome_screen.py index d23392a548f5..1ca487c91a7d 100644 --- a/discord/welcome_screen.py +++ b/discord/welcome_screen.py @@ -214,4 +214,4 @@ async def edit( fields['enabled'] = enabled data = await self._state.http.edit_welcome_screen(self._guild.id, reason=reason, **fields) - return WelcomeScreen(data=data, guild=self._guild) + return self.__class__(data=data, guild=self._guild)