Skip to content

Commit 7eda7e4

Browse files
chore: resolve lint and typing issues
1 parent 9695975 commit 7eda7e4

File tree

6 files changed

+54
-89
lines changed

6 files changed

+54
-89
lines changed

disnake/app_commands.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def __init__(
468468
name: LocalizedRequired,
469469
dm_permission: Optional[bool] = None,
470470
default_member_permissions: Optional[Union[Permissions, int]] = None,
471-
id: int = None,
471+
id: Optional[int] = None,
472472
):
473473
self.type: ApplicationCommandType = enum_if_int(ApplicationCommandType, type)
474474

@@ -605,7 +605,7 @@ def __init__(
605605
name: LocalizedRequired,
606606
dm_permission: Optional[bool] = None,
607607
default_member_permissions: Optional[Union[Permissions, int]] = None,
608-
id: int = None,
608+
id: Optional[int] = None,
609609
):
610610
super().__init__(
611611
type=ApplicationCommandType.user,
@@ -693,7 +693,7 @@ def __init__(
693693
name: LocalizedRequired,
694694
dm_permission: Optional[bool] = None,
695695
default_member_permissions: Optional[Union[Permissions, int]] = None,
696-
id: int = None,
696+
id: Optional[int] = None,
697697
):
698698
super().__init__(
699699
type=ApplicationCommandType.message,
@@ -799,7 +799,7 @@ def __init__(
799799
options: Optional[List[Option]] = None,
800800
dm_permission: Optional[bool] = None,
801801
default_member_permissions: Optional[Union[Permissions, int]] = None,
802-
id: int = None,
802+
id: Optional[int] = None,
803803
):
804804
super().__init__(
805805
type=ApplicationCommandType.chat_input,

disnake/ext/commands/errors.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,9 @@ class CommandRegistrationError(ClientException):
10161016
Whether the name that conflicts is an alias of the command we try to add.
10171017
"""
10181018

1019-
def __init__(self, name: str, *, alias_conflict: bool = False, guild_id: int = None) -> None:
1019+
def __init__(
1020+
self, name: str, *, alias_conflict: bool = False, guild_id: Optional[int] = None
1021+
) -> None:
10201022
self.name: str = name
10211023
self.alias_conflict: bool = alias_conflict
10221024
self.guild_id: Optional[int] = guild_id

disnake/ext/commands/flags.py

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
"""
2-
The MIT License (MIT)
3-
4-
Copyright (c) 2015-2021 Rapptz
5-
Copyright (c) 2021-present Disnake Development
6-
7-
Permission is hereby granted, free of charge, to any person obtaining a
8-
copy of this software and associated documentation files (the "Software"),
9-
to deal in the Software without restriction, including without limitation
10-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
11-
and/or sell copies of the Software, and to permit persons to whom the
12-
Software is furnished to do so, subject to the following conditions:
13-
14-
The above copyright notice and this permission notice shall be included in
15-
all copies or substantial portions of the Software.
16-
17-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23-
DEALINGS IN THE SOFTWARE.
24-
"""
1+
# SPDX-License-Identifier: MIT
2+
253
from __future__ import annotations
264

275
from typing import TYPE_CHECKING
286

29-
from disnake.flags import BaseFlags, alias_flag_value, all_flags_value, fill_with_flags, flag_value
7+
from disnake.flags import BaseFlags, alias_flag_value, all_flags_value, flag_value
308

319
if TYPE_CHECKING:
3210
from typing_extensions import Self
3311

3412
__all__ = ("ApplicationCommandSyncFlags",)
3513

3614

37-
@fill_with_flags()
3815
class ApplicationCommandSyncFlags(BaseFlags):
3916
"""Controls the library's application command syncing policy.
4017

disnake/ext/commands/interaction_bot_base.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class InteractionBotBase(CommonBotBase):
142142
def __init__(
143143
self,
144144
*,
145-
command_sync: ApplicationCommandSyncFlags = None,
145+
command_sync: Optional[ApplicationCommandSyncFlags] = None,
146146
test_guilds: Optional[Sequence[int]] = None,
147147
**options: Any,
148148
):
@@ -178,9 +178,7 @@ def __init__(
178178
self._schedule_app_command_preparation()
179179

180180
def application_commands_iterator(self) -> Iterable[InvokableApplicationCommand]:
181-
return chain(
182-
self._all_app_commands.values(),
183-
)
181+
yield from self._all_app_commands.values()
184182

185183
@property
186184
def all_app_commands(self) -> List[InvokableApplicationCommand]:
@@ -371,7 +369,7 @@ def add_message_command(self, message_command: InvokableMessageCommand) -> None:
371369
] = message_command
372370

373371
def remove_slash_command(
374-
self, name: str, *, guild_id: int = None
372+
self, name: str, *, guild_id: Optional[int] = None
375373
) -> Optional[InvokableSlashCommand]:
376374
"""Removes an :class:`InvokableSlashCommand` from the internal list
377375
of slash commands.
@@ -400,7 +398,7 @@ def remove_slash_command(
400398
return command
401399

402400
def remove_user_command(
403-
self, name: str, *, guild_id: int = None
401+
self, name: str, *, guild_id: Optional[int] = None
404402
) -> Optional[InvokableUserCommand]:
405403
"""Removes an :class:`InvokableUserCommand` from the internal list
406404
of user commands.
@@ -422,7 +420,7 @@ def remove_user_command(
422420
return command
423421

424422
def remove_message_command(
425-
self, name: str, *, guild_id: int = None
423+
self, name: str, *, guild_id: Optional[int] = None
426424
) -> Optional[InvokableMessageCommand]:
427425
"""Removes an :class:`InvokableMessageCommand` from the internal list
428426
of message commands.
@@ -445,24 +443,36 @@ def remove_message_command(
445443

446444
@overload
447445
def get_app_command(
448-
self, name: str, type: Literal[ApplicationCommandType.chat_input], *, guild_id: int = None
446+
self,
447+
name: str,
448+
type: Literal[ApplicationCommandType.chat_input],
449+
*,
450+
guild_id: Optional[int] = None,
449451
) -> Optional[InvokableSlashCommand]:
450452
...
451453

452454
@overload
453455
def get_app_command(
454-
self, name: str, type: Literal[ApplicationCommandType.message], *, guild_id: int = None
456+
self,
457+
name: str,
458+
type: Literal[ApplicationCommandType.message],
459+
*,
460+
guild_id: Optional[int] = None,
455461
) -> Optional[InvokableMessageCommand]:
456462
...
457463

458464
@overload
459465
def get_app_command(
460-
self, name: str, type: Literal[ApplicationCommandType.user], *, guild_id: int = None
466+
self,
467+
name: str,
468+
type: Literal[ApplicationCommandType.user],
469+
*,
470+
guild_id: Optional[int] = None,
461471
) -> Optional[InvokableUserCommand]:
462472
...
463473

464474
def get_app_command(
465-
self, name: str, type: ApplicationCommandType, *, guild_id: int = None
475+
self, name: str, type: ApplicationCommandType, *, guild_id: Optional[int] = None
466476
) -> Optional[InvokableApplicationCommand]:
467477
# this does not get commands by ID, use (some other method) to do that
468478
if not isinstance(name, str):
@@ -473,7 +483,7 @@ def get_app_command(
473483
return command
474484

475485
def get_slash_command(
476-
self, name: str, *, guild_id: int = None
486+
self, name: str, *, guild_id: Optional[int] = None
477487
) -> Optional[Union[InvokableSlashCommand, SubCommandGroup, SubCommand]]:
478488
"""Works like ``Bot.get_command``, but for slash commands.
479489
@@ -515,7 +525,7 @@ def get_slash_command(
515525
return group.children.get(chain[2])
516526

517527
def get_user_command(
518-
self, name: str, *, guild_id: int = None
528+
self, name: str, *, guild_id: Optional[int] = None
519529
) -> Optional[InvokableUserCommand]:
520530
"""Gets an :class:`InvokableUserCommand` from the internal list
521531
of user commands.
@@ -533,7 +543,7 @@ def get_user_command(
533543
return self.get_app_command(name, ApplicationCommandType.user, guild_id=guild_id)
534544

535545
def get_message_command(
536-
self, name: str, *, guild_id: int = None
546+
self, name: str, *, guild_id: Optional[int] = None
537547
) -> Optional[InvokableMessageCommand]:
538548
"""Gets an :class:`InvokableMessageCommand` from the internal list
539549
of message commands.

disnake/ext/commands/slash_core.py

+19-43
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,11 @@ def root_parent(self) -> InvokableSlashCommand:
176176

177177
@property
178178
def parents(self) -> Tuple[InvokableSlashCommand]:
179-
"""Tuple[:class:`InvokableSlashCommand`]: Returns all parents of this group.
179+
"""Tuple[:class:`InvokableSlashCommand`]: Retrieves the parents of this command.
180+
181+
If the command has no parents then it returns an empty :class:`tuple`.
182+
183+
For example in commands ``/a b test``, the parents are ``(b, a)``.
180184
181185
.. versionadded:: 2.6
182186
"""
@@ -195,25 +199,10 @@ def mention(self) -> str:
195199
# todo: add docs and make ID non-nullable
196200
return f"</{self.qualified_name}:{self.id}>"
197201

198-
# todo: refactor this class to make this not optional
199202
@property
200-
def parent(self) -> Optional[InvokableSlashCommand]:
203+
def parent(self) -> InvokableSlashCommand:
201204
return self._parent
202205

203-
@property
204-
def parents(
205-
self,
206-
) -> Tuple[InvokableSlashCommand]:
207-
"""Tuple[:class:`InvokableSlashCommand`]: Retrieves the parents of this command.
208-
209-
If the command has no parents then it returns an empty :class:`tuple`.
210-
211-
For example in commands ``/a b test``, the parents are ``(b, a)``.
212-
213-
.. versionadded:: 2.6
214-
"""
215-
return (self.parent,) # type: ignore
216-
217206
def sub_command(
218207
self,
219208
name: LocalizedOptional = None,
@@ -344,7 +333,7 @@ def root_parent(self) -> InvokableSlashCommand:
344333
345334
.. versionadded:: 2.6
346335
"""
347-
return self.parent.parent if isinstance(self.parent, SubCommandGroup) else self.parent
336+
return self._parent._parent if isinstance(self._parent, SubCommandGroup) else self._parent
348337

349338
@property
350339
def parents(
@@ -357,10 +346,10 @@ def parents(
357346
358347
.. versionadded:: 2.6
359348
"""
360-
# here I'm not using 'self.parent.parents + (self.parent,)' because it causes typing issues
361-
if isinstance(self.parent, SubCommandGroup):
362-
return (self.parent, self.parent.parent)
363-
return (self.parent,)
349+
# here I'm not using 'self._parent._parents + (self._parent,)' because it causes typing issues
350+
if isinstance(self._parent, SubCommandGroup):
351+
return (self._parent, self._parent._parent)
352+
return (self._parent,)
364353

365354
@property
366355
def description(self) -> str:
@@ -382,29 +371,9 @@ def mention(self) -> str:
382371
return f"</{self.qualified_name}:{self.id}>"
383372

384373
@property
385-
def parent(self) -> Optional[Union[InvokableSlashCommand, SubCommandGroup]]:
374+
def parent(self) -> Union[InvokableSlashCommand, SubCommandGroup]:
386375
return self._parent
387376

388-
@property
389-
def parents(
390-
self,
391-
) -> Union[Tuple[InvokableSlashCommand], Tuple[SubCommandGroup, InvokableSlashCommand]]:
392-
"""Union[Tuple[:class:`InvokableSlashCommand`], Tuple[:class:`SubCommandGroup`, :class:`InvokableSlashCommand`]]: Retrieves the parents of this command.
393-
394-
If the command has no parents then it returns an empty :class:`tuple`.
395-
396-
For example in commands ``/a b test``, the parents are ``(b, a)``.
397-
398-
.. versionadded:: 2.6
399-
"""
400-
entries = []
401-
command = self
402-
while command.parent is not None: # type: ignore
403-
command = command.parent # type: ignore
404-
entries.append(command)
405-
406-
return tuple(entries)
407-
408377
async def _call_autocompleter(
409378
self, param: str, inter: ApplicationCommandInteraction, user_input: str
410379
) -> Optional[Choices]:
@@ -560,6 +529,13 @@ def parents(self) -> Tuple[()]:
560529
"""
561530
return ()
562531

532+
@property
533+
def parent(self) -> None:
534+
"""``None``: This is for consistency with :class:`SubCommand` and :class:`SubCommandGroup`.
535+
536+
.. versionadded:: 2.6
537+
"""
538+
563539
def _ensure_assignment_on_copy(self, other: SlashCommandT) -> SlashCommandT:
564540
super()._ensure_assignment_on_copy(other)
565541
if self.connectors != other.connectors:

test_bot/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self):
3232
command_prefix=Config.prefix,
3333
intents=disnake.Intents.all(),
3434
help_command=None, # type: ignore
35-
sync_commands_debug=Config.sync_commands_debug,
35+
command_sync=commands.ApplicationCommandSyncFlags.all(),
3636
strict_localization=Config.strict_localization,
3737
test_guilds=Config.test_guilds,
3838
reload=Config.auto_reload,

0 commit comments

Comments
 (0)