From d7070193489cf0e6dc0b4128fa4c56009d25c025 Mon Sep 17 00:00:00 2001 From: Bryan Forbes Date: Thu, 4 Aug 2022 21:46:02 -0500 Subject: [PATCH] Bump Pyright to 1.1.265, fix type errors, and remove unnecessary ignores --- .github/workflows/lint.yml | 2 +- discord/abc.py | 6 +++--- discord/activity.py | 2 +- discord/app_commands/models.py | 2 +- discord/client.py | 4 ++-- discord/ext/commands/converter.py | 2 +- discord/ext/commands/core.py | 6 +++--- discord/ext/commands/help.py | 4 ++-- discord/ext/commands/hybrid.py | 4 ++-- discord/ext/tasks/__init__.py | 8 ++++---- discord/gateway.py | 2 +- discord/guild.py | 8 ++++---- discord/scheduled_event.py | 4 ++-- discord/state.py | 6 +++--- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4f9d25930..a0fa17b93 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.253' + version: '1.1.265' warnings: false no-comments: ${{ matrix.python-version != '3.x' }} diff --git a/discord/abc.py b/discord/abc.py index 6121e7555..85cea03af 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1696,7 +1696,7 @@ class Messageable: The message with the message data parsed. """ - async def _around_strategy(retrieve, around, limit): + async def _around_strategy(retrieve: int, around: Optional[Snowflake], limit: Optional[int]): if not around: return [] @@ -1705,7 +1705,7 @@ class Messageable: return data, None, limit - async def _after_strategy(retrieve, after, limit): + 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.logs_from(channel.id, retrieve, after=after_id) @@ -1717,7 +1717,7 @@ class Messageable: return data, after, limit - async def _before_strategy(retrieve, before, limit): + 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.logs_from(channel.id, retrieve, before=before_id) diff --git a/discord/activity.py b/discord/activity.py index 27d5ec20b..662f592c0 100644 --- a/discord/activity.py +++ b/discord/activity.py @@ -822,7 +822,7 @@ def create_activity(data: Optional[ActivityPayload], state: ConnectionState) -> return Game(**data) elif game_type is ActivityType.custom: try: - name = data.pop('name') + name = data.pop('name') # type: ignore except KeyError: ret = Activity(**data) else: diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index 494031d45..9fe66c45a 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -442,7 +442,7 @@ class Choice(Generic[ChoiceT]): ) def to_dict(self) -> ApplicationCommandOptionChoice: - return { + return { # type: ignore 'name': self.name, 'value': self.value, } diff --git a/discord/client.py b/discord/client.py index b9c1d4135..226e6e3ff 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1442,7 +1442,7 @@ class Client: The guild with the guild data parsed. """ - async def _before_strategy(retrieve, before, limit): + async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[int]): before_id = before.id if before else None data = await self.http.get_guilds(retrieve, before=before_id) @@ -1454,7 +1454,7 @@ class Client: return data, before, limit - async def _after_strategy(retrieve, after, limit): + async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[int]): after_id = after.id if after else None data = await self.http.get_guilds(retrieve, after=after_id) diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 32f0fbb5c..a41898333 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1198,7 +1198,7 @@ async def _actual_conversion(ctx: Context[BotT], converter: Any, argument: str, if inspect.ismethod(converter.convert): return await converter.convert(ctx, argument) else: - return await converter().convert(ctx, argument) # type: ignore + return await converter().convert(ctx, argument) elif isinstance(converter, Converter): return await converter.convert(ctx, argument) # type: ignore except CommandError: diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 7b08d7103..5e1232769 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -888,7 +888,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): if self._max_concurrency is not None: # For this application, context can be duck-typed as a Message - await self._max_concurrency.acquire(ctx) # type: ignore + await self._max_concurrency.acquire(ctx) try: if self.cooldown_after_parsing: @@ -901,7 +901,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): await self.call_before_hooks(ctx) except: if self._max_concurrency is not None: - await self._max_concurrency.release(ctx) # type: ignore + await self._max_concurrency.release(ctx) raise def is_on_cooldown(self, ctx: Context[BotT], /) -> bool: @@ -2426,7 +2426,7 @@ def cooldown( if isinstance(func, Command): func._buckets = CooldownMapping(Cooldown(rate, per), type) else: - func.__commands_cooldown__ = CooldownMapping(Cooldown(rate, per), type) # type: ignore # typevar cannot be inferred without annotation + func.__commands_cooldown__ = CooldownMapping(Cooldown(rate, per), type) return func return decorator # type: ignore diff --git a/discord/ext/commands/help.py b/discord/ext/commands/help.py index 66115e910..c82b617d4 100644 --- a/discord/ext/commands/help.py +++ b/discord/ext/commands/help.py @@ -220,7 +220,7 @@ def _not_overridden(f: FuncT) -> FuncT: class _HelpCommandImpl(Command): def __init__(self, inject: HelpCommand, *args: Any, **kwargs: Any) -> None: - super().__init__(inject.command_callback, *args, **kwargs) # type: ignore + super().__init__(inject.command_callback, *args, **kwargs) self._original: HelpCommand = inject self._injected: HelpCommand = inject self.params: Dict[str, Parameter] = get_signature_parameters(inject.command_callback, globals(), skip_parameters=1) @@ -228,7 +228,7 @@ class _HelpCommandImpl(Command): async def prepare(self, ctx: Context[Any]) -> None: self._injected = injected = self._original.copy() injected.context = ctx - self.callback = injected.command_callback # type: ignore + self.callback = injected.command_callback self.params = get_signature_parameters(injected.command_callback, globals(), skip_parameters=1) on_error = injected.on_help_command_error diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 6def19126..10aa928dd 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -140,7 +140,7 @@ class ConverterTransformer(app_commands.Transformer): if inspect.ismethod(converter.convert): return await converter.convert(ctx, value) else: - return await converter().convert(ctx, value) # type: ignore + return await converter().convert(ctx, value) elif isinstance(converter, Converter): return await converter.convert(ctx, value) except CommandError: @@ -205,7 +205,7 @@ def replace_parameter( args = getattr(converter, '__args__', []) if isinstance(converter, Range): r = converter - param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max]) # type: ignore + param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max]) elif isinstance(converter, Greedy): # Greedy is "optional" in ext.commands # However, in here, it probably makes sense to make it required. diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 651a14c04..bf0697568 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -29,8 +29,8 @@ import datetime import logging from typing import ( Any, - Awaitable, Callable, + Coroutine, Generic, List, Optional, @@ -56,10 +56,10 @@ __all__ = ( # fmt: on T = TypeVar('T') -_func = Callable[..., Awaitable[Any]] +_func = Callable[..., Coroutine[Any, Any, Any]] LF = TypeVar('LF', bound=_func) FT = TypeVar('FT', bound=_func) -ET = TypeVar('ET', bound=Callable[[Any, BaseException], Awaitable[Any]]) +ET = TypeVar('ET', bound=Callable[[Any, BaseException], Coroutine[Any, Any, Any]]) def is_ambiguous(dt: datetime.datetime) -> bool: @@ -619,7 +619,7 @@ class Loop(Generic[LF]): if not inspect.iscoroutinefunction(coro): raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.') - self._error = coro # type: ignore + self._error = coro return coro def _get_next_sleep_time(self, now: datetime.datetime = MISSING) -> datetime.datetime: diff --git a/discord/gateway.py b/discord/gateway.py index aa190feee..3bb58af36 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -812,7 +812,7 @@ class DiscordVoiceWebSocket: self._close_code: Optional[int] = None self.secret_key: Optional[str] = None if hook: - self._hook = hook # type: ignore # type-checker doesn't like overriding methods + self._hook = hook async def _hook(self, *args: Any) -> None: pass diff --git a/discord/guild.py b/discord/guild.py index 00366b904..a58078337 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2227,7 +2227,7 @@ class Guild(Hashable): # This endpoint paginates in ascending order. endpoint = self._state.http.get_bans - async def _before_strategy(retrieve, before, limit): + async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[int]): before_id = before.id if before else None data = await endpoint(self.id, limit=retrieve, before=before_id) @@ -2239,7 +2239,7 @@ class Guild(Hashable): return data, before, limit - async def _after_strategy(retrieve, after, limit): + async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[int]): after_id = after.id if after else None data = await endpoint(self.id, limit=retrieve, after=after_id) @@ -3539,7 +3539,7 @@ class Guild(Hashable): The audit log entry. """ - async def _before_strategy(retrieve, before, limit): + 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 @@ -3555,7 +3555,7 @@ class Guild(Hashable): return data, entries, before, limit - async def _after_strategy(retrieve, after, limit): + 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 diff --git a/discord/scheduled_event.py b/discord/scheduled_event.py index eec81a0e0..a6f88dabd 100644 --- a/discord/scheduled_event.py +++ b/discord/scheduled_event.py @@ -512,7 +512,7 @@ class ScheduledEvent(Hashable): All subscribed users of this event. """ - async def _before_strategy(retrieve, before, limit): + async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[int]): before_id = before.id if before else None users = await self._state.http.get_scheduled_event_users( self.guild_id, self.id, limit=retrieve, with_member=False, before=before_id @@ -526,7 +526,7 @@ class ScheduledEvent(Hashable): return users, before, limit - async def _after_strategy(retrieve, after, limit): + async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[int]): after_id = after.id if after else None users = await self._state.http.get_scheduled_event_users( self.guild_id, self.id, limit=retrieve, with_member=False, after=after_id diff --git a/discord/state.py b/discord/state.py index 25eda0632..81390e701 100644 --- a/discord/state.py +++ b/discord/state.py @@ -247,7 +247,7 @@ class ConnectionState: self._command_tree: Optional[CommandTree] = None if not intents.members or cache_flags._empty: - self.store_user = self.store_user_no_intents # type: ignore # This reassignment is on purpose + self.store_user = self.store_user_no_intents self.parsers: Dict[str, Callable[[Any], None]] self.parsers = parsers = {} @@ -1329,7 +1329,7 @@ class ConnectionState: _log.debug('GUILD_INTEGRATIONS_UPDATE referencing an unknown guild ID: %s. Discarding.', data['guild_id']) def parse_integration_create(self, data: gw.IntegrationCreateEvent) -> None: - guild_id = int(data.pop('guild_id')) + guild_id = int(data['guild_id']) guild = self._get_guild(guild_id) if guild is not None: cls, _ = _integration_factory(data['type']) @@ -1339,7 +1339,7 @@ class ConnectionState: _log.debug('INTEGRATION_CREATE referencing an unknown guild ID: %s. Discarding.', guild_id) def parse_integration_update(self, data: gw.IntegrationUpdateEvent) -> None: - guild_id = int(data.pop('guild_id')) + guild_id = int(data['guild_id']) guild = self._get_guild(guild_id) if guild is not None: cls, _ = _integration_factory(data['type'])