Update to pyright 1.1.242

This commit is contained in:
Rapptz 2022-04-30 19:37:01 -04:00
parent 8be103d6bb
commit 5536ef1eea
7 changed files with 23 additions and 27 deletions

View File

@ -38,7 +38,7 @@ jobs:
- name: Run Pyright - name: Run Pyright
uses: jakebailey/pyright-action@v1 uses: jakebailey/pyright-action@v1
with: with:
version: '1.1.237' version: '1.1.242'
warnings: false warnings: false
no-comments: ${{ matrix.python-version != '3.x' }} no-comments: ${{ matrix.python-version != '3.x' }}

View File

@ -711,12 +711,8 @@ class Command(Generic[GroupT, P, T]):
return False return False
if self.binding is not None: if self.binding is not None:
try: check: Optional[Check] = getattr(self.binding, 'interaction_check', None)
# Type checker does not like runtime attribute retrieval if check:
check: Check = self.binding.interaction_check # type: ignore
except AttributeError:
pass
else:
ret = await maybe_coroutine(check, interaction) ret = await maybe_coroutine(check, interaction)
if not ret: if not ret:
return False return False

View File

@ -1004,7 +1004,8 @@ class CommandTree(Generic[ClientT]):
resolved = Namespace._get_resolved_items(interaction, data.get('resolved', {})) 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 # Right now, the only types are message and user
# Therefore, there's no conflict with snowflakes # Therefore, there's no conflict with snowflakes

View File

@ -508,8 +508,7 @@ class Cog(metaclass=CogMeta):
command.cog = self command.cog = self
if command.parent is None: if command.parent is None:
try: try:
# Type checker does not understand the generic bounds here bot.add_command(command)
bot.add_command(command) # type: ignore
except Exception as e: except Exception as e:
# undo our additions # undo our additions
for to_undo in self.__cog_commands__[:index]: for to_undo in self.__cog_commands__[:index]:

View File

@ -259,7 +259,7 @@ class MemberConverter(IDConverter[discord.Member]):
if not result: if not result:
raise MemberNotFound(argument) raise MemberNotFound(argument)
return result # type: ignore return result
class UserConverter(IDConverter[discord.User]): class UserConverter(IDConverter[discord.User]):
@ -336,7 +336,7 @@ class PartialMessageConverter(Converter[discord.PartialMessage]):
""" """
@staticmethod @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<channel_id>[0-9]{15,20})-)?(?P<message_id>[0-9]{15,20})$') id_regex = re.compile(r'(?:(?P<channel_id>[0-9]{15,20})-)?(?P<message_id>[0-9]{15,20})$')
link_regex = re.compile( link_regex = re.compile(
r'https?://(?:(ptb|canary|www)\.)?discord(?:app)?\.com/channels/' 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) guild_id, message_id, channel_id = self._get_id_matches(ctx, argument)
channel = self._resolve_channel(ctx, guild_id, channel_id) channel = self._resolve_channel(ctx, guild_id, channel_id)
if not channel or not isinstance(channel, discord.abc.Messageable): 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) 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: if converter is bool:
return _convert_to_bool(argument) return _convert_to_bool(argument)
@ -1182,7 +1182,7 @@ async def _actual_conversion(ctx: Context[BotT], converter, argument: str, param
except CommandError: except CommandError:
raise raise
except Exception as exc: except Exception as exc:
raise ConversionError(converter, exc) from exc # type: ignore raise ConversionError(converter, exc) from exc
try: try:
return converter(argument) return converter(argument)
@ -1192,7 +1192,7 @@ async def _actual_conversion(ctx: Context[BotT], converter, argument: str, param
try: try:
name = converter.__name__ name = converter.__name__
except AttributeError: 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 raise BadArgument(f'Converting to "{name}" failed for parameter "{param.name}".') from exc

View File

@ -577,11 +577,11 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
except AttributeError: except AttributeError:
pass pass
else: else:
injected = wrap_callback(coro) injected = wrap_callback(coro) # type: ignore
if cog is not None: if cog is not None:
await injected(cog, ctx, error) # type: ignore await injected(cog, ctx, error)
else: else:
await injected(ctx, error) await injected(ctx, error) # type: ignore
try: try:
if cog is not None: if cog is not None:
@ -944,7 +944,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
# the invoked subcommand is None. # the invoked subcommand is None.
ctx.invoked_subcommand = None ctx.invoked_subcommand = None
ctx.subcommand_passed = 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 await injected(*ctx.args, **ctx.kwargs) # type: ignore
async def reinvoke(self, ctx: Context[BotT], /, *, call_hooks: bool = False) -> None: 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) greedy = isinstance(param.converter, Greedy)
optional = False # postpone evaluation of if it's an optional argument 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) origin = getattr(annotation, '__origin__', None)
if not greedy and origin is Union: if not greedy and origin is Union:
none_cls = type(None) none_cls = type(None)
union_args = annotation.__args__ # type: ignore # this is safe union_args = annotation.__args__
optional = union_args[-1] is none_cls optional = union_args[-1] is none_cls
if len(union_args) == 2 and optional: if len(union_args) == 2 and optional:
annotation = union_args[0] 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 # for typing.Literal[...], typing.Optional[typing.Literal[...]], and Greedy[typing.Literal[...]], the
# parameter signature is a literal list of it's values # parameter signature is a literal list of it's values
if origin is Literal: 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: if not param.required:
# We don't want None or '' to trigger the [name=value] case and instead it should # 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. # 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) ctx.invoked_subcommand = self.all_commands.get(trigger, None)
if early_invoke: 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 await injected(*ctx.args, **ctx.kwargs) # type: ignore
ctx.invoked_parents.append(ctx.invoked_with) # type: ignore ctx.invoked_parents.append(ctx.invoked_with) # type: ignore
@ -1837,8 +1837,8 @@ def check(predicate: Check[ContextT], /) -> Callable[[T], T]:
else: else:
@functools.wraps(predicate) @functools.wraps(predicate)
async def wrapper(ctx): async def wrapper(ctx: ContextT):
return predicate(ctx) # type: ignore return predicate(ctx)
decorator.predicate = wrapper decorator.predicate = wrapper

View File

@ -127,7 +127,7 @@ def make_converter_transformer(converter: Any) -> Type[app_commands.Transformer]
except CommandError: except CommandError:
raise raise
except Exception as exc: 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)}) return type('ConverterTransformer', (app_commands.Transformer,), {'transform': classmethod(transform)})