diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ee68539e4..6c5a0d268 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.237' + version: '1.1.242' warnings: false no-comments: ${{ matrix.python-version != '3.x' }} diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index cda5e2b4c..818603fe1 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -711,12 +711,8 @@ class Command(Generic[GroupT, P, T]): return False if self.binding is not None: - try: - # Type checker does not like runtime attribute retrieval - check: Check = self.binding.interaction_check # type: ignore - except AttributeError: - pass - else: + check: Optional[Check] = getattr(self.binding, 'interaction_check', None) + if check: ret = await maybe_coroutine(check, interaction) if not ret: return False diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index f9e0a3d93..a845e20f0 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -1004,7 +1004,8 @@ class CommandTree(Generic[ClientT]): resolved = Namespace._get_resolved_items(interaction, data.get('resolved', {})) - target_id = data.get('target_id') + # This is annotated as str | int but realistically this will always be str + target_id: Optional[Union[str, int]] = data.get('target_id') # Right now, the only types are message and user # Therefore, there's no conflict with snowflakes diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index eed5eff40..5a8ddcb1e 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -508,8 +508,7 @@ class Cog(metaclass=CogMeta): command.cog = self if command.parent is None: try: - # Type checker does not understand the generic bounds here - bot.add_command(command) # type: ignore + bot.add_command(command) except Exception as e: # undo our additions for to_undo in self.__cog_commands__[:index]: diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py index 4a49c30dd..21a7553ee 100644 --- a/discord/ext/commands/converter.py +++ b/discord/ext/commands/converter.py @@ -259,7 +259,7 @@ class MemberConverter(IDConverter[discord.Member]): if not result: raise MemberNotFound(argument) - return result # type: ignore + return result class UserConverter(IDConverter[discord.User]): @@ -336,7 +336,7 @@ class PartialMessageConverter(Converter[discord.PartialMessage]): """ @staticmethod - def _get_id_matches(ctx, argument): + def _get_id_matches(ctx: Context[BotT], argument: str) -> Tuple[Optional[int], int, int]: id_regex = re.compile(r'(?:(?P[0-9]{15,20})-)?(?P[0-9]{15,20})$') link_regex = re.compile( r'https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/' @@ -378,7 +378,7 @@ class PartialMessageConverter(Converter[discord.PartialMessage]): guild_id, message_id, channel_id = self._get_id_matches(ctx, argument) channel = self._resolve_channel(ctx, guild_id, channel_id) if not channel or not isinstance(channel, discord.abc.Messageable): - raise ChannelNotFound(channel_id) # type: ignore # channel_id won't be None here + raise ChannelNotFound(channel_id) return discord.PartialMessage(channel=channel, id=message_id) @@ -1159,7 +1159,7 @@ CONVERTER_MAPPING: Dict[type, Any] = { } -async def _actual_conversion(ctx: Context[BotT], converter, argument: str, param: inspect.Parameter): +async def _actual_conversion(ctx: Context[BotT], converter: Any, argument: str, param: inspect.Parameter): if converter is bool: return _convert_to_bool(argument) @@ -1182,7 +1182,7 @@ async def _actual_conversion(ctx: Context[BotT], converter, argument: str, param except CommandError: raise except Exception as exc: - raise ConversionError(converter, exc) from exc # type: ignore + raise ConversionError(converter, exc) from exc try: return converter(argument) @@ -1192,7 +1192,7 @@ async def _actual_conversion(ctx: Context[BotT], converter, argument: str, param try: name = converter.__name__ except AttributeError: - name = converter.__class__.__name__ # type: ignore + name = converter.__class__.__name__ raise BadArgument(f'Converting to "{name}" failed for parameter "{param.name}".') from exc diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 4845cfff2..896c7ddd3 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -577,11 +577,11 @@ class Command(_BaseCommand, Generic[CogT, P, T]): except AttributeError: pass else: - injected = wrap_callback(coro) + injected = wrap_callback(coro) # type: ignore if cog is not None: - await injected(cog, ctx, error) # type: ignore + await injected(cog, ctx, error) else: - await injected(ctx, error) + await injected(ctx, error) # type: ignore try: if cog is not None: @@ -944,7 +944,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): # the invoked subcommand is None. ctx.invoked_subcommand = None ctx.subcommand_passed = None - injected = hooked_wrapped_callback(self, ctx, self.callback) + injected = hooked_wrapped_callback(self, ctx, self.callback) # type: ignore await injected(*ctx.args, **ctx.kwargs) # type: ignore async def reinvoke(self, ctx: Context[BotT], /, *, call_hooks: bool = False) -> None: @@ -1098,11 +1098,11 @@ class Command(_BaseCommand, Generic[CogT, P, T]): greedy = isinstance(param.converter, Greedy) optional = False # postpone evaluation of if it's an optional argument - annotation = param.converter.converter if greedy else param.converter # type: ignore # needs conditional types + annotation: Any = param.converter.converter if greedy else param.converter origin = getattr(annotation, '__origin__', None) if not greedy and origin is Union: none_cls = type(None) - union_args = annotation.__args__ # type: ignore # this is safe + union_args = annotation.__args__ optional = union_args[-1] is none_cls if len(union_args) == 2 and optional: annotation = union_args[0] @@ -1111,7 +1111,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): # for typing.Literal[...], typing.Optional[typing.Literal[...]], and Greedy[typing.Literal[...]], the # parameter signature is a literal list of it's values if origin is Literal: - name = '|'.join(f'"{v}"' if isinstance(v, str) else str(v) for v in annotation.__args__) # type: ignore # this is safe + name = '|'.join(f'"{v}"' if isinstance(v, str) else str(v) for v in annotation.__args__) if not param.required: # We don't want None or '' to trigger the [name=value] case and instead it should # do [name] since [name=None] or [name=] are not exactly useful for the user. @@ -1547,7 +1547,7 @@ class Group(GroupMixin[CogT], Command[CogT, P, T]): ctx.invoked_subcommand = self.all_commands.get(trigger, None) if early_invoke: - injected = hooked_wrapped_callback(self, ctx, self.callback) + injected = hooked_wrapped_callback(self, ctx, self.callback) # type: ignore await injected(*ctx.args, **ctx.kwargs) # type: ignore ctx.invoked_parents.append(ctx.invoked_with) # type: ignore @@ -1837,8 +1837,8 @@ def check(predicate: Check[ContextT], /) -> Callable[[T], T]: else: @functools.wraps(predicate) - async def wrapper(ctx): - return predicate(ctx) # type: ignore + async def wrapper(ctx: ContextT): + return predicate(ctx) decorator.predicate = wrapper diff --git a/discord/ext/commands/hybrid.py b/discord/ext/commands/hybrid.py index 95ccc9389..641d8185c 100644 --- a/discord/ext/commands/hybrid.py +++ b/discord/ext/commands/hybrid.py @@ -127,7 +127,7 @@ def make_converter_transformer(converter: Any) -> Type[app_commands.Transformer] except CommandError: raise except Exception as exc: - raise ConversionError(converter, exc) from exc # type: ignore + raise ConversionError(converter, exc) from exc return type('ConverterTransformer', (app_commands.Transformer,), {'transform': classmethod(transform)})