Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 4ed7f3a

Browse files
committed
Update Pyright to v1.1.394
1 parent b5aef72 commit 4ed7f3a

30 files changed

+94
-81
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Run Pyright
3939
uses: jakebailey/pyright-action@v1
4040
with:
41-
version: '1.1.351'
41+
version: '1.1.394'
4242
warnings: false
4343
no-comments: ${{ matrix.python-version != '3.x' }}
4444

discord/abc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
GuildChannel as GuildChannelPayload,
103103
OverwriteType,
104104
)
105+
from .types.guild import (
106+
ChannelPositionUpdate,
107+
)
105108
from .types.snowflake import (
106109
SnowflakeList,
107110
)
@@ -1232,11 +1235,11 @@ async def move(self, **kwargs: Any) -> None:
12321235
raise ValueError('Could not resolve appropriate move position')
12331236

12341237
channels.insert(max((index + offset), 0), self)
1235-
payload = []
1238+
payload: List[ChannelPositionUpdate] = []
12361239
lock_permissions = kwargs.get('sync_permissions', False)
12371240
reason = kwargs.get('reason')
12381241
for index, channel in enumerate(channels):
1239-
d = {'id': channel.id, 'position': index}
1242+
d: ChannelPositionUpdate = {'id': channel.id, 'position': index}
12401243
if parent_id is not MISSING and channel.id == self.id:
12411244
d.update(parent_id=parent_id, lock_permissions=lock_permissions)
12421245
payload.append(d)

discord/activity.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def to_dict(self) -> Dict[str, Any]:
273273
def start(self) -> Optional[datetime.datetime]:
274274
"""Optional[:class:`datetime.datetime`]: When the user started doing this activity in UTC, if applicable."""
275275
try:
276-
timestamp = self.timestamps['start'] / 1000
276+
timestamp = self.timestamps['start'] / 1000 # pyright: ignore[reportTypedDictNotRequiredAccess]
277277
except KeyError:
278278
return None
279279
else:
@@ -283,7 +283,7 @@ def start(self) -> Optional[datetime.datetime]:
283283
def end(self) -> Optional[datetime.datetime]:
284284
"""Optional[:class:`datetime.datetime`]: When the user will stop doing this activity in UTC, if applicable."""
285285
try:
286-
timestamp = self.timestamps['end'] / 1000
286+
timestamp = self.timestamps['end'] / 1000 # pyright: ignore[reportTypedDictNotRequiredAccess]
287287
except KeyError:
288288
return None
289289
else:
@@ -293,7 +293,7 @@ def end(self) -> Optional[datetime.datetime]:
293293
def large_image_url(self) -> Optional[str]:
294294
"""Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
295295
try:
296-
large_image = self.assets['large_image']
296+
large_image = self.assets['large_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
297297
except KeyError:
298298
return None
299299
else:
@@ -303,7 +303,7 @@ def large_image_url(self) -> Optional[str]:
303303
def small_image_url(self) -> Optional[str]:
304304
"""Optional[:class:`str`]: Returns a URL pointing to the small image asset of this activity, if applicable."""
305305
try:
306-
small_image = self.assets['small_image']
306+
small_image = self.assets['small_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
307307
except KeyError:
308308
return None
309309
else:
@@ -525,7 +525,7 @@ def twitch_name(self) -> Optional[str]:
525525
"""
526526

527527
try:
528-
name = self.assets['large_image']
528+
name = self.assets['large_image'] # pyright: ignore[reportTypedDictNotRequiredAccess]
529529
except KeyError:
530530
return None
531531
else:

discord/app_commands/commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ async def _invoke_autocomplete(self, interaction: Interaction, name: str, namesp
903903
predicates = getattr(param.autocomplete, '__discord_app_commands_checks__', [])
904904
if predicates:
905905
try:
906-
passed = await async_all(f(interaction) for f in predicates)
906+
passed = await async_all(f(interaction) for f in predicates) # type: ignore
907907
except Exception:
908908
passed = False
909909

@@ -1014,7 +1014,7 @@ async def _check_can_run(self, interaction: Interaction) -> bool:
10141014
if not predicates:
10151015
return True
10161016

1017-
return await async_all(f(interaction) for f in predicates)
1017+
return await async_all(f(interaction) for f in predicates) # type: ignore
10181018

10191019
def error(self, coro: Error[GroupT]) -> Error[GroupT]:
10201020
"""A decorator that registers a coroutine as a local error handler.
@@ -1308,7 +1308,7 @@ async def _check_can_run(self, interaction: Interaction) -> bool:
13081308
if not predicates:
13091309
return True
13101310

1311-
return await async_all(f(interaction) for f in predicates)
1311+
return await async_all(f(interaction) for f in predicates) # type: ignore
13121312

13131313
def _has_any_error_handlers(self) -> bool:
13141314
return self.on_error is not None
@@ -1842,7 +1842,7 @@ def error(self, coro: ErrorFunc) -> ErrorFunc:
18421842
if len(params) != 2:
18431843
raise TypeError('The error handler must have 2 parameters.')
18441844

1845-
self.on_error = coro
1845+
self.on_error = coro # type: ignore
18461846
return coro
18471847

18481848
async def interaction_check(self, interaction: Interaction, /) -> bool:

discord/app_commands/transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def __call__(self) -> None:
235235
pass
236236

237237
def __or__(self, rhs: Any) -> Any:
238-
return Union[self, rhs] # type: ignore
238+
return Union[self, rhs]
239239

240240
@property
241241
def type(self) -> AppCommandOptionType:

discord/app_commands/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def error(self, coro: ErrorFunc[ClientT]) -> ErrorFunc[ClientT]:
859859
if len(params) != 2:
860860
raise TypeError('error handler must have 2 parameters')
861861

862-
self.on_error = coro
862+
self.on_error = coro # type: ignore
863863
return coro
864864

865865
def command(

discord/components.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ def __init__(self, data: ButtonComponentPayload, /) -> None:
196196
self.label: Optional[str] = data.get('label')
197197
self.emoji: Optional[PartialEmoji]
198198
try:
199-
self.emoji = PartialEmoji.from_dict(data['emoji'])
199+
self.emoji = PartialEmoji.from_dict(data['emoji']) # pyright: ignore[reportTypedDictNotRequiredAccess]
200200
except KeyError:
201201
self.emoji = None
202202

203203
try:
204-
self.sku_id: Optional[int] = int(data['sku_id'])
204+
self.sku_id: Optional[int] = int(data['sku_id']) # pyright: ignore[reportTypedDictNotRequiredAccess]
205205
except KeyError:
206206
self.sku_id = None
207207

@@ -415,7 +415,7 @@ def emoji(self, value: Optional[Union[str, Emoji, PartialEmoji]]) -> None:
415415
@classmethod
416416
def from_dict(cls, data: SelectOptionPayload) -> SelectOption:
417417
try:
418-
emoji = PartialEmoji.from_dict(data['emoji'])
418+
emoji = PartialEmoji.from_dict(data['emoji']) # pyright: ignore[reportTypedDictNotRequiredAccess]
419419
except KeyError:
420420
emoji = None
421421

discord/enums.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ def _create_value_cls(name: str, comparable: bool):
8484
# All the type ignores here are due to the type checker being unable to recognise
8585
# Runtime type creation without exploding.
8686
cls = namedtuple('_EnumValue_' + name, 'name value')
87-
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>' # type: ignore
88-
cls.__str__ = lambda self: f'{name}.{self.name}' # type: ignore
87+
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>'
88+
cls.__str__ = lambda self: f'{name}.{self.name}'
8989
if comparable:
90-
cls.__le__ = lambda self, other: isinstance(other, self.__class__) and self.value <= other.value # type: ignore
91-
cls.__ge__ = lambda self, other: isinstance(other, self.__class__) and self.value >= other.value # type: ignore
92-
cls.__lt__ = lambda self, other: isinstance(other, self.__class__) and self.value < other.value # type: ignore
93-
cls.__gt__ = lambda self, other: isinstance(other, self.__class__) and self.value > other.value # type: ignore
90+
cls.__le__ = lambda self, other: isinstance(other, self.__class__) and self.value <= other.value
91+
cls.__ge__ = lambda self, other: isinstance(other, self.__class__) and self.value >= other.value
92+
cls.__lt__ = lambda self, other: isinstance(other, self.__class__) and self.value < other.value
93+
cls.__gt__ = lambda self, other: isinstance(other, self.__class__) and self.value > other.value
9494
return cls
9595

9696

discord/ext/commands/bot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def __init__(
172172
**options: Any,
173173
) -> None:
174174
super().__init__(intents=intents, **options)
175-
self.command_prefix: PrefixType[BotT] = command_prefix
175+
self.command_prefix: PrefixType[BotT] = command_prefix # type: ignore
176176
self.extra_events: Dict[str, List[CoroFunc]] = {}
177177
# Self doesn't have the ClientT bound, but since this is a mixin it technically does
178178
self.__tree: app_commands.CommandTree[Self] = tree_cls(self) # type: ignore
@@ -487,7 +487,7 @@ async def can_run(self, ctx: Context[BotT], /, *, call_once: bool = False) -> bo
487487
if len(data) == 0:
488488
return True
489489

490-
return await discord.utils.async_all(f(ctx) for f in data)
490+
return await discord.utils.async_all(f(ctx) for f in data) # type: ignore
491491

492492
async def is_owner(self, user: User, /) -> bool:
493493
"""|coro|

discord/ext/commands/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def is_cog(obj: Any) -> TypeGuard[Cog]:
8282
return hasattr(obj, '__cog_commands__')
8383

8484

85-
class DeferTyping:
85+
class DeferTyping(Generic[BotT]):
8686
def __init__(self, ctx: Context[BotT], *, ephemeral: bool):
8787
self.ctx: Context[BotT] = ctx
8888
self.ephemeral: bool = ephemeral

discord/ext/commands/converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ def __class_getitem__(cls, params: Union[Tuple[T], T]) -> Greedy[T]:
11251125

11261126
args = getattr(converter, '__args__', ())
11271127
if discord.utils.PY_310 and converter.__class__ is types.UnionType: # type: ignore
1128-
converter = Union[args] # type: ignore
1128+
converter = Union[args]
11291129

11301130
origin = getattr(converter, '__origin__', None)
11311131

@@ -1138,7 +1138,7 @@ def __class_getitem__(cls, params: Union[Tuple[T], T]) -> Greedy[T]:
11381138
if origin is Union and type(None) in args:
11391139
raise TypeError(f'Greedy[{converter!r}] is invalid.')
11401140

1141-
return cls(converter=converter)
1141+
return cls(converter=converter) # type: ignore
11421142

11431143
@property
11441144
def constructed_converter(self) -> Any:
@@ -1325,7 +1325,7 @@ async def _actual_conversion(ctx: Context[BotT], converter: Any, argument: str,
13251325
else:
13261326
return await converter().convert(ctx, argument)
13271327
elif isinstance(converter, Converter):
1328-
return await converter.convert(ctx, argument) # type: ignore
1328+
return await converter.convert(ctx, argument)
13291329
except CommandError:
13301330
raise
13311331
except Exception as exc:

discord/ext/commands/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ async def can_run(self, ctx: Context[BotT], /) -> bool:
12851285
# since we have no checks, then we just return True.
12861286
return True
12871287

1288-
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
1288+
return await discord.utils.async_all(predicate(ctx) for predicate in predicates) # type: ignore
12891289
finally:
12901290
ctx.command = original
12911291

discord/ext/commands/errors.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@
2424

2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union
27+
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Tuple, Union, Generic
2828

2929
from discord.errors import ClientException, DiscordException
3030
from discord.utils import _human_join
3131

32+
from ._types import BotT
33+
3234
if TYPE_CHECKING:
3335
from discord.abc import GuildChannel
3436
from discord.threads import Thread
3537
from discord.types.snowflake import Snowflake, SnowflakeList
3638
from discord.app_commands import AppCommandError
3739

38-
from ._types import BotT
3940
from .context import Context
4041
from .converter import Converter
4142
from .cooldowns import BucketType, Cooldown
@@ -235,7 +236,7 @@ class CheckFailure(CommandError):
235236
pass
236237

237238

238-
class CheckAnyFailure(CheckFailure):
239+
class CheckAnyFailure(Generic[BotT], CheckFailure):
239240
"""Exception raised when all predicates in :func:`check_any` fail.
240241
241242
This inherits from :exc:`CheckFailure`.

discord/ext/commands/flags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ async def convert_flag(ctx: Context[BotT], argument: str, flag: Flag, annotation
443443
return await convert_flag(ctx, argument, flag, annotation)
444444
elif origin is Union and type(None) in annotation.__args__:
445445
# typing.Optional[x]
446-
annotation = Union[tuple(arg for arg in annotation.__args__ if arg is not type(None))] # type: ignore
446+
annotation = Union[tuple(arg for arg in annotation.__args__ if arg is not type(None))]
447447
return await run_converters(ctx, annotation, argument, param)
448448
elif origin is dict:
449449
# typing.Dict[K, V] -> typing.Tuple[K, V]

discord/ext/commands/hybrid.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ def replace_parameter(
203203
# Fallback to see if the behaviour needs changing
204204
origin = getattr(converter, '__origin__', None)
205205
args = getattr(converter, '__args__', [])
206-
if isinstance(converter, Range):
206+
if isinstance(converter, Range): # type: ignore # Range is not an Annotation at runtime
207207
r = converter
208-
param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max])
208+
param = param.replace(annotation=app_commands.Range[r.annotation, r.min, r.max]) # type: ignore
209209
elif isinstance(converter, Greedy):
210210
# Greedy is "optional" in ext.commands
211211
# However, in here, it probably makes sense to make it required.
@@ -257,7 +257,7 @@ def replace_parameter(
257257
inner = args[0]
258258
is_inner_transformer = is_transformer(inner)
259259
if is_converter(inner) and not is_inner_transformer:
260-
param = param.replace(annotation=Optional[ConverterTransformer(inner, original)]) # type: ignore
260+
param = param.replace(annotation=Optional[ConverterTransformer(inner, original)])
261261
else:
262262
raise
263263
elif origin:
@@ -424,10 +424,10 @@ async def _check_can_run(self, interaction: discord.Interaction) -> bool:
424424
if not ret:
425425
return False
426426

427-
if self.checks and not await async_all(f(interaction) for f in self.checks):
427+
if self.checks and not await async_all(f(interaction) for f in self.checks): # type: ignore
428428
return False
429429

430-
if self.wrapped.checks and not await async_all(f(ctx) for f in self.wrapped.checks):
430+
if self.wrapped.checks and not await async_all(f(ctx) for f in self.wrapped.checks): # type: ignore
431431
return False
432432

433433
return True
@@ -915,7 +915,8 @@ def hybrid_command(
915915
def decorator(func: CommandCallback[CogT, ContextT, P, T]) -> HybridCommand[CogT, P, T]:
916916
if isinstance(func, Command):
917917
raise TypeError('Callback is already a command.')
918-
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs)
918+
# Pyright does not allow Command[Any] to be assigned to Command[CogT] despite it being okay here
919+
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) # type: ignore
919920

920921
return decorator
921922

discord/gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def __init__(
831831
self._close_code: Optional[int] = None
832832
self.secret_key: Optional[List[int]] = None
833833
if hook:
834-
self._hook = hook
834+
self._hook = hook # type: ignore
835835

836836
async def _hook(self, *args: Any) -> None:
837837
pass
@@ -893,7 +893,7 @@ async def from_connection_state(
893893

894894
return ws
895895

896-
async def select_protocol(self, ip: str, port: int, mode: int) -> None:
896+
async def select_protocol(self, ip: str, port: int, mode: str) -> None:
897897
payload = {
898898
'op': self.SELECT_PROTOCOL,
899899
'd': {

discord/guild.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ def _update_voice_state(self, data: GuildVoiceState, channel_id: int) -> Tuple[O
551551
member = self.get_member(user_id)
552552
if member is None:
553553
try:
554-
member = Member(data=data['member'], state=self._state, guild=self)
554+
member_data = data['member'] # pyright: ignore[reportTypedDictNotRequiredAccess]
555+
member = Member(data=member_data, state=self._state, guild=self)
555556
except KeyError:
556557
member = None
557558

@@ -573,7 +574,7 @@ def _create_unavailable(cls, *, state: ConnectionState, guild_id: int, data: Opt
573574

574575
def _from_data(self, guild: GuildPayload) -> None:
575576
try:
576-
self._member_count = guild['member_count']
577+
self._member_count = guild['member_count'] # pyright: ignore[reportTypedDictNotRequiredAccess]
577578
except KeyError:
578579
pass
579580

discord/interactions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@ def _from_data(self, data: InteractionPayload):
219219
int(k): int(v) for k, v in data.get('authorizing_integration_owners', {}).items()
220220
}
221221
try:
222-
self.context = AppCommandContext._from_value([data['context']])
222+
value = data['context'] # pyright: ignore[reportTypedDictNotRequiredAccess]
223+
self.context = AppCommandContext._from_value([value])
223224
except KeyError:
224225
self.context = AppCommandContext()
225226

226227
self.locale: Locale = try_enum(Locale, data.get('locale', 'en-US'))
227228
self.guild_locale: Optional[Locale]
228229
try:
229-
self.guild_locale = try_enum(Locale, data['guild_locale'])
230+
self.guild_locale = try_enum(Locale, data['guild_locale']) # pyright: ignore[reportTypedDictNotRequiredAccess]
230231
except KeyError:
231232
self.guild_locale = None
232233

discord/invite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def __init__(
437437
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
438438
guild: Optional[Union[Guild, PartialInviteGuild]]
439439
try:
440-
guild_data = data['guild']
440+
guild_data = data['guild'] # pyright: ignore[reportTypedDictNotRequiredAccess]
441441
except KeyError:
442442
# If we're here, then this is a group DM
443443
guild = None

0 commit comments

Comments
 (0)