Browse Source

Update to pyright 1.1.242

pull/10109/head
Rapptz 3 years ago
committed by dolfies
parent
commit
18120c4726
  1. 4
      .github/workflows/lint.yml
  2. 3
      discord/ext/commands/cog.py
  3. 12
      discord/ext/commands/converter.py
  4. 20
      discord/ext/commands/core.py

4
.github/workflows/lint.yml

@ -33,7 +33,11 @@ jobs:
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
<<<<<<< HEAD
version: '1.1.235'
=======
version: '1.1.242'
>>>>>>> 5536ef1e (Update to pyright 1.1.242)
warnings: false
no-comments: ${{ matrix.python-version != '3.x' }}

3
discord/ext/commands/cog.py

@ -453,8 +453,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]:

12
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<channel_id>[0-9]{15,20})-)?(?P<message_id>[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)
@ -1149,7 +1149,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)
@ -1172,7 +1172,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)
@ -1182,7 +1182,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

20
discord/ext/commands/core.py

@ -566,11 +566,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:
@ -933,7 +933,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:
@ -1087,11 +1087,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]
@ -1100,7 +1100,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.
@ -1536,7 +1536,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
@ -1826,8 +1826,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

Loading…
Cancel
Save