From b9795979acd107a427edf4fdd21042d05a079256 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/application.py | 4 ++-- discord/client.py | 6 +++--- discord/ext/commands/converter.py | 2 +- discord/ext/commands/core.py | 6 +++--- discord/ext/tasks/__init__.py | 8 ++++---- discord/gateway.py | 2 +- discord/guild.py | 8 ++++---- discord/scheduled_event.py | 4 ++-- discord/state.py | 6 +++--- discord/team.py | 2 +- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 98a9992be..112b3eb07 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -33,7 +33,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 1198bce4f..62f564d29 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1806,7 +1806,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 [] @@ -1815,7 +1815,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) @@ -1827,7 +1827,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 802c1654c..034894208 100644 --- a/discord/activity.py +++ b/discord/activity.py @@ -1035,7 +1035,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/application.py b/discord/application.py index b421111a5..a08917302 100644 --- a/discord/application.py +++ b/discord/application.py @@ -2935,7 +2935,7 @@ class Application(PartialApplication): _state = self._state - async def _after_strategy(retrieve, after, limit): + async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[Snowflake]): after_id = after.id if after else None data = await _state.http.get_app_entitlements( self.id, @@ -2956,7 +2956,7 @@ class Application(PartialApplication): return data, after, limit - async def _before_strategy(retrieve, before, limit): + async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[Snowflake]): before_id = before.id if before else None data = await _state.http.get_app_entitlements( self.id, diff --git a/discord/client.py b/discord/client.py index ffb62d883..e77e84ba3 100644 --- a/discord/client.py +++ b/discord/client.py @@ -3743,7 +3743,7 @@ class Client: _state = self._connection - async def _after_strategy(retrieve, after, limit): + async def _after_strategy(retrieve: int, after: Optional[Snowflake], limit: Optional[Snowflake]): after_id = after.id if after else None data = await _state.http.get_payments(retrieve, after=after_id) @@ -3755,7 +3755,7 @@ class Client: return data, after, limit - async def _before_strategy(retrieve, before, limit): + async def _before_strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[Snowflake]): before_id = before.id if before else None data = await _state.http.get_payments(retrieve, before=before_id) @@ -4590,7 +4590,7 @@ class Client: """ _state = self._connection - async def strategy(retrieve, before, limit): + async def strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[Snowflake]): before_id = before.id if before else None data = await _state.http.get_recent_mentions( retrieve, before=before_id, guild_id=guild.id if guild else None, roles=roles, everyone=everyone diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 2cabc858a..1185067bf 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -1185,7 +1185,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 ae93e3630..4cbf26a27 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -878,7 +878,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: @@ -891,7 +891,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: @@ -2351,7 +2351,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/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 532705017..25d7a4a99 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -912,7 +912,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 2779b458f..31910066c 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2233,7 +2233,7 @@ class Guild(Hashable): yield BanEntry(user=User(state=_state, data=entry['user']), reason=entry['reason']) return - 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) @@ -2245,7 +2245,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) @@ -3503,7 +3503,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 @@ -3519,7 +3519,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 4b49b8a62..f65c20f22 100644 --- a/discord/scheduled_event.py +++ b/discord/scheduled_event.py @@ -499,7 +499,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 @@ -514,7 +514,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 bfc566f8d..795dd7482 100644 --- a/discord/state.py +++ b/discord/state.py @@ -578,7 +578,7 @@ class ConnectionState: self._status: Optional[str] = status if cache_flags._empty: - self.store_user = self.create_user # type: ignore # This reassignment is on purpose + self.store_user = self.create_user self.parsers: Dict[str, Callable[[Any], None]] self.parsers = parsers = {} @@ -2303,7 +2303,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']) @@ -2313,7 +2313,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']) diff --git a/discord/team.py b/discord/team.py index dd6a12012..81acfd240 100644 --- a/discord/team.py +++ b/discord/team.py @@ -412,7 +412,7 @@ class Team(Hashable): The payout received. """ - async def strategy(retrieve, before, limit): + async def strategy(retrieve: int, before: Optional[Snowflake], limit: Optional[Snowflake]): before_id = before.id if before else None data = await self._state.http.get_team_payouts(self.id, limit=retrieve, before=before_id)