diff --git a/.libcst.codemod.yaml b/.libcst.codemod.yaml index 7f40b15ead..61e307f445 100644 --- a/.libcst.codemod.yaml +++ b/.libcst.codemod.yaml @@ -6,7 +6,7 @@ generated_code_marker: '@generated_module' # Command line and arguments for invoking a code formatter. Anything # specified here must be capable of taking code via stdin and returning # formatted code via stdout. -formatter: ['black', '-q' , '-'] +formatter: ['ruff', 'format' , '-'] # List of regex patterns which LibCST will evaluate against filenames to # determine if the module should be touched. blacklist_patterns: [] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4209dcf8d6..78c97f769f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,14 +37,9 @@ repos: exclude_types: [json, pofile] exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in' - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.9.1 - hooks: - - id: black - name: "run black in all files" - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.8.0 + rev: v0.9.3 hooks: + - id: ruff-format - id: ruff args: [--fix, --fixable=I] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60c31f2f44..d0251bda47 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,7 +70,7 @@ Once PDM is installed, use the following command to initialize a virtual environ $ pdm run setup_env ``` -Other tools used in this project include [black](https://black.readthedocs.io/en/stable/) (formatter), [ruff](https://beta.ruff.rs/docs/) (linter), and [pyright](https://microsoft.github.io/pyright/#/) (type-checker). For the most part, these automatically run on every commit with no additional action required - see below for details. +Other tools used in this project include [ruff](https://docs.astral.sh/ruff) (formatter and linter), and [pyright](https://microsoft.github.io/pyright/#/) (type-checker). For the most part, these automatically run on every commit with no additional action required - see below for details. All of the following checks also automatically run for every PR on GitHub, so don't worry if you're not sure whether you missed anything. A PR cannot be merged as long as there are any failing checks. diff --git a/disnake/abc.py b/disnake/abc.py index a80952f536..85c63dd592 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -269,8 +269,7 @@ class GuildChannel(ABC): def __init__( self, *, state: ConnectionState, guild: Guild, data: Mapping[str, Any] - ) -> None: - ... + ) -> None: ... def __str__(self) -> str: return self.name @@ -843,8 +842,7 @@ async def set_permissions( *, overwrite: Optional[PermissionOverwrite] = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload @_overload_with_permissions @@ -911,8 +909,7 @@ async def set_permissions( view_channel: Optional[bool] = ..., view_creator_monetization_analytics: Optional[bool] = ..., view_guild_insights: Optional[bool] = ..., - ) -> None: - ... + ) -> None: ... async def set_permissions( self, @@ -1118,8 +1115,7 @@ async def move( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -1130,8 +1126,7 @@ async def move( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -1142,8 +1137,7 @@ async def move( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -1154,8 +1148,7 @@ async def move( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... async def move(self, **kwargs: Any) -> None: """|coro| @@ -1442,8 +1435,7 @@ async def send( view: View = ..., components: Components[MessageUIComponent] = ..., poll: Poll = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def send( @@ -1464,8 +1456,7 @@ async def send( view: View = ..., components: Components[MessageUIComponent] = ..., poll: Poll = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def send( @@ -1486,8 +1477,7 @@ async def send( view: View = ..., components: Components[MessageUIComponent] = ..., poll: Poll = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def send( @@ -1508,8 +1498,7 @@ async def send( view: View = ..., components: Components[MessageUIComponent] = ..., poll: Poll = ..., - ) -> Message: - ... + ) -> Message: ... async def send( self, diff --git a/disnake/activity.py b/disnake/activity.py index 3c290edd17..97c4381c14 100644 --- a/disnake/activity.py +++ b/disnake/activity.py @@ -890,13 +890,11 @@ def __repr__(self) -> str: @overload def create_activity( data: Union[ActivityPayload, WidgetActivityPayload], *, state: Optional[ConnectionState] = None -) -> ActivityTypes: - ... +) -> ActivityTypes: ... @overload -def create_activity(data: None, *, state: Optional[ConnectionState] = None) -> None: - ... +def create_activity(data: None, *, state: Optional[ConnectionState] = None) -> None: ... def create_activity( diff --git a/disnake/audit_logs.py b/disnake/audit_logs.py index 1a71095822..0a90b14d9c 100644 --- a/disnake/audit_logs.py +++ b/disnake/audit_logs.py @@ -216,7 +216,7 @@ def _transform(entry: AuditLogEntry, data: Optional[int]) -> Optional[FlagsT]: def _list_transformer( - func: Callable[[AuditLogEntry, Any], T] + func: Callable[[AuditLogEntry, Any], T], ) -> Callable[[AuditLogEntry, Any], List[T]]: def _transform(entry: AuditLogEntry, data: Any) -> List[T]: if not data: @@ -303,11 +303,9 @@ def __repr__(self) -> str: if TYPE_CHECKING: - def __getattr__(self, item: str) -> Any: - ... + def __getattr__(self, item: str) -> Any: ... - def __setattr__(self, key: str, value: Any) -> Any: - ... + def __setattr__(self, key: str, value: Any) -> Any: ... Transformer = Callable[["AuditLogEntry", Any], Any] diff --git a/disnake/automod.py b/disnake/automod.py index f07fe6f95c..35b0e82fed 100644 --- a/disnake/automod.py +++ b/disnake/automod.py @@ -296,8 +296,7 @@ def __init__( keyword_filter: Optional[Sequence[str]], regex_patterns: Optional[Sequence[str]] = None, allow_list: Optional[Sequence[str]] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -306,8 +305,7 @@ def __init__( keyword_filter: Optional[Sequence[str]] = None, regex_patterns: Optional[Sequence[str]], allow_list: Optional[Sequence[str]] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -315,14 +313,12 @@ def __init__( *, presets: AutoModKeywordPresets, allow_list: Optional[Sequence[str]] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( self, *, mention_total_limit: int, mention_raid_protection_enabled: bool = False - ) -> None: - ... + ) -> None: ... def __init__( self, diff --git a/disnake/backoff.py b/disnake/backoff.py index 949ec07963..1f54e226ff 100644 --- a/disnake/backoff.py +++ b/disnake/backoff.py @@ -50,16 +50,13 @@ def __init__(self, base: int = 1, *, integral: T = False) -> None: ) @overload - def delay(self: ExponentialBackoff[Literal[False]]) -> float: - ... + def delay(self: ExponentialBackoff[Literal[False]]) -> float: ... @overload - def delay(self: ExponentialBackoff[Literal[True]]) -> int: - ... + def delay(self: ExponentialBackoff[Literal[True]]) -> int: ... @overload - def delay(self: ExponentialBackoff[bool]) -> Union[int, float]: - ... + def delay(self: ExponentialBackoff[bool]) -> Union[int, float]: ... def delay(self) -> Union[int, float]: """Compute the next delay diff --git a/disnake/channel.py b/disnake/channel.py index d7c72ca5a1..800d618001 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -395,8 +395,7 @@ async def edit( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... # only passing `sync_permissions` may or may not return a channel, # depending on whether the channel is in a category @@ -406,8 +405,7 @@ async def edit( *, sync_permissions: bool, reason: Optional[str] = ..., - ) -> Optional[TextChannel]: - ... + ) -> Optional[TextChannel]: ... @overload async def edit( @@ -426,8 +424,7 @@ async def edit( overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ..., flags: ChannelFlags = ..., reason: Optional[str] = ..., - ) -> TextChannel: - ... + ) -> TextChannel: ... async def edit( self, @@ -992,8 +989,7 @@ async def create_thread( auto_archive_duration: Optional[AnyThreadArchiveDuration] = None, slowmode_delay: Optional[int] = None, reason: Optional[str] = None, - ) -> Thread: - ... + ) -> Thread: ... @overload async def create_thread( @@ -1005,8 +1001,7 @@ async def create_thread( invitable: Optional[bool] = None, slowmode_delay: Optional[int] = None, reason: Optional[str] = None, - ) -> Thread: - ... + ) -> Thread: ... async def create_thread( self, @@ -1550,8 +1545,7 @@ async def edit( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... # only passing `sync_permissions` may or may not return a channel, # depending on whether the channel is in a category @@ -1561,8 +1555,7 @@ async def edit( *, sync_permissions: bool, reason: Optional[str] = ..., - ) -> Optional[VoiceChannel]: - ... + ) -> Optional[VoiceChannel]: ... @overload async def edit( @@ -1581,8 +1574,7 @@ async def edit( slowmode_delay: Optional[int] = ..., flags: ChannelFlags = ..., reason: Optional[str] = ..., - ) -> VoiceChannel: - ... + ) -> VoiceChannel: ... async def edit( self, @@ -2398,8 +2390,7 @@ async def edit( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... # only passing `sync_permissions` may or may not return a channel, # depending on whether the channel is in a category @@ -2409,8 +2400,7 @@ async def edit( *, sync_permissions: bool, reason: Optional[str] = ..., - ) -> Optional[StageChannel]: - ... + ) -> Optional[StageChannel]: ... @overload async def edit( @@ -2429,8 +2419,7 @@ async def edit( slowmode_delay: Optional[int] = ..., flags: ChannelFlags = ..., reason: Optional[str] = ..., - ) -> StageChannel: - ... + ) -> StageChannel: ... async def edit( self, @@ -2960,8 +2949,7 @@ async def edit( *, position: int, reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def edit( @@ -2973,8 +2961,7 @@ async def edit( overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = ..., flags: ChannelFlags = ..., reason: Optional[str] = ..., - ) -> CategoryChannel: - ... + ) -> CategoryChannel: ... async def edit( self, @@ -3060,8 +3047,7 @@ async def move( offset: int = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -3071,8 +3057,7 @@ async def move( offset: int = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -3082,8 +3067,7 @@ async def move( offset: int = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @overload async def move( @@ -3093,8 +3077,7 @@ async def move( offset: int = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... @utils.copy_doc(disnake.abc.GuildChannel.move) async def move(self, **kwargs: Any) -> None: @@ -3503,8 +3486,7 @@ async def create_thread( view: View = ..., components: Components = ..., reason: Optional[str] = None, - ) -> ThreadWithMessage: - ... + ) -> ThreadWithMessage: ... @overload async def create_thread( @@ -3524,8 +3506,7 @@ async def create_thread( view: View = ..., components: Components = ..., reason: Optional[str] = None, - ) -> ThreadWithMessage: - ... + ) -> ThreadWithMessage: ... @overload async def create_thread( @@ -3545,8 +3526,7 @@ async def create_thread( view: View = ..., components: Components = ..., reason: Optional[str] = None, - ) -> ThreadWithMessage: - ... + ) -> ThreadWithMessage: ... @overload async def create_thread( @@ -3566,8 +3546,7 @@ async def create_thread( view: View = ..., components: Components = ..., reason: Optional[str] = None, - ) -> ThreadWithMessage: - ... + ) -> ThreadWithMessage: ... async def create_thread( self, @@ -4000,8 +3979,7 @@ async def edit( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... # only passing `sync_permissions` may or may not return a channel, # depending on whether the channel is in a category @@ -4011,8 +3989,7 @@ async def edit( *, sync_permissions: bool, reason: Optional[str] = ..., - ) -> Optional[ForumChannel]: - ... + ) -> Optional[ForumChannel]: ... @overload async def edit( @@ -4035,8 +4012,7 @@ async def edit( default_sort_order: Optional[ThreadSortOrder] = ..., default_layout: ThreadLayout = ..., reason: Optional[str] = ..., - ) -> ForumChannel: - ... + ) -> ForumChannel: ... async def edit( self, @@ -4430,8 +4406,7 @@ async def edit( category: Optional[Snowflake] = ..., sync_permissions: bool = ..., reason: Optional[str] = ..., - ) -> None: - ... + ) -> None: ... # only passing `sync_permissions` may or may not return a channel, # depending on whether the channel is in a category @@ -4441,8 +4416,7 @@ async def edit( *, sync_permissions: bool, reason: Optional[str] = ..., - ) -> Optional[MediaChannel]: - ... + ) -> Optional[MediaChannel]: ... @overload async def edit( @@ -4464,8 +4438,7 @@ async def edit( default_reaction: Optional[Union[str, Emoji, PartialEmoji]] = ..., default_sort_order: Optional[ThreadSortOrder] = ..., reason: Optional[str] = ..., - ) -> MediaChannel: - ... + ) -> MediaChannel: ... async def edit( self, @@ -5160,7 +5133,7 @@ def _threaded_guild_channel_factory(channel_type: int): def _channel_type_factory( - cls: Union[Type[disnake.abc.GuildChannel], Type[Thread]] + cls: Union[Type[disnake.abc.GuildChannel], Type[Thread]], ) -> List[ChannelType]: return { # FIXME: this includes private channels; improve this once there's a common base type for all channels diff --git a/disnake/client.py b/disnake/client.py index c87213d2f2..915aa8159d 100644 --- a/disnake/client.py +++ b/disnake/client.py @@ -677,12 +677,10 @@ def get_message(self, id: int) -> Optional[Message]: @overload async def get_or_fetch_user( self, user_id: int, *, strict: Literal[False] = ... - ) -> Optional[User]: - ... + ) -> Optional[User]: ... @overload - async def get_or_fetch_user(self, user_id: int, *, strict: Literal[True]) -> User: - ... + async def get_or_fetch_user(self, user_id: int, *, strict: Literal[True]) -> User: ... async def get_or_fetch_user(self, user_id: int, *, strict: bool = False) -> Optional[User]: """|coro| @@ -2738,22 +2736,20 @@ async def fetch_global_command(self, command_id: int) -> APIApplicationCommand: return await self._connection.fetch_global_command(command_id) @overload - async def create_global_command(self, application_command: SlashCommand) -> APISlashCommand: - ... + async def create_global_command(self, application_command: SlashCommand) -> APISlashCommand: ... @overload - async def create_global_command(self, application_command: UserCommand) -> APIUserCommand: - ... + async def create_global_command(self, application_command: UserCommand) -> APIUserCommand: ... @overload - async def create_global_command(self, application_command: MessageCommand) -> APIMessageCommand: - ... + async def create_global_command( + self, application_command: MessageCommand + ) -> APIMessageCommand: ... @overload async def create_global_command( self, application_command: ApplicationCommand - ) -> APIApplicationCommand: - ... + ) -> APIApplicationCommand: ... async def create_global_command( self, application_command: ApplicationCommand @@ -2780,26 +2776,22 @@ async def create_global_command( @overload async def edit_global_command( self, command_id: int, new_command: SlashCommand - ) -> APISlashCommand: - ... + ) -> APISlashCommand: ... @overload async def edit_global_command( self, command_id: int, new_command: UserCommand - ) -> APIUserCommand: - ... + ) -> APIUserCommand: ... @overload async def edit_global_command( self, command_id: int, new_command: MessageCommand - ) -> APIMessageCommand: - ... + ) -> APIMessageCommand: ... @overload async def edit_global_command( self, command_id: int, new_command: ApplicationCommand - ) -> APIApplicationCommand: - ... + ) -> APIApplicationCommand: ... async def edit_global_command( self, command_id: int, new_command: ApplicationCommand @@ -2918,26 +2910,22 @@ async def fetch_guild_command(self, guild_id: int, command_id: int) -> APIApplic @overload async def create_guild_command( self, guild_id: int, application_command: SlashCommand - ) -> APISlashCommand: - ... + ) -> APISlashCommand: ... @overload async def create_guild_command( self, guild_id: int, application_command: UserCommand - ) -> APIUserCommand: - ... + ) -> APIUserCommand: ... @overload async def create_guild_command( self, guild_id: int, application_command: MessageCommand - ) -> APIMessageCommand: - ... + ) -> APIMessageCommand: ... @overload async def create_guild_command( self, guild_id: int, application_command: ApplicationCommand - ) -> APIApplicationCommand: - ... + ) -> APIApplicationCommand: ... async def create_guild_command( self, guild_id: int, application_command: ApplicationCommand @@ -2966,26 +2954,22 @@ async def create_guild_command( @overload async def edit_guild_command( self, guild_id: int, command_id: int, new_command: SlashCommand - ) -> APISlashCommand: - ... + ) -> APISlashCommand: ... @overload async def edit_guild_command( self, guild_id: int, command_id: int, new_command: UserCommand - ) -> APIUserCommand: - ... + ) -> APIUserCommand: ... @overload async def edit_guild_command( self, guild_id: int, command_id: int, new_command: MessageCommand - ) -> APIMessageCommand: - ... + ) -> APIMessageCommand: ... @overload async def edit_guild_command( self, guild_id: int, command_id: int, new_command: ApplicationCommand - ) -> APIApplicationCommand: - ... + ) -> APIApplicationCommand: ... async def edit_guild_command( self, guild_id: int, command_id: int, new_command: ApplicationCommand diff --git a/disnake/embeds.py b/disnake/embeds.py index abbbff53f2..f243ae8e89 100644 --- a/disnake/embeds.py +++ b/disnake/embeds.py @@ -386,12 +386,10 @@ def footer(self) -> _EmbedFooterProxy: return cast("_EmbedFooterProxy", EmbedProxy(self._footer)) @overload - def set_footer(self, *, text: Any, icon_url: Optional[Any] = ...) -> Self: - ... + def set_footer(self, *, text: Any, icon_url: Optional[Any] = ...) -> Self: ... @overload - def set_footer(self, *, text: Any, icon_file: File = ...) -> Self: - ... + def set_footer(self, *, text: Any, icon_file: File = ...) -> Self: ... def set_footer( self, *, text: Any, icon_url: Optional[Any] = MISSING, icon_file: File = MISSING @@ -463,12 +461,10 @@ def image(self) -> _EmbedMediaProxy: return cast("_EmbedMediaProxy", EmbedProxy(self._image)) @overload - def set_image(self, url: Optional[Any]) -> Self: - ... + def set_image(self, url: Optional[Any]) -> Self: ... @overload - def set_image(self, *, file: File) -> Self: - ... + def set_image(self, *, file: File) -> Self: ... def set_image(self, url: Optional[Any] = MISSING, *, file: File = MISSING) -> Self: """Sets the image for the embed content. @@ -518,12 +514,10 @@ def thumbnail(self) -> _EmbedMediaProxy: return cast("_EmbedMediaProxy", EmbedProxy(self._thumbnail)) @overload - def set_thumbnail(self, url: Optional[Any]) -> Self: - ... + def set_thumbnail(self, url: Optional[Any]) -> Self: ... @overload - def set_thumbnail(self, *, file: File) -> Self: - ... + def set_thumbnail(self, *, file: File) -> Self: ... def set_thumbnail(self, url: Optional[Any] = MISSING, *, file: File = MISSING) -> Self: """Sets the thumbnail for the embed content. @@ -595,12 +589,10 @@ def author(self) -> _EmbedAuthorProxy: @overload def set_author( self, *, name: Any, url: Optional[Any] = ..., icon_url: Optional[Any] = ... - ) -> Self: - ... + ) -> Self: ... @overload - def set_author(self, *, name: Any, url: Optional[Any] = ..., icon_file: File = ...) -> Self: - ... + def set_author(self, *, name: Any, url: Optional[Any] = ..., icon_file: File = ...) -> Self: ... def set_author( self, diff --git a/disnake/ext/commands/base_core.py b/disnake/ext/commands/base_core.py index c513c977db..0ee4aab860 100644 --- a/disnake/ext/commands/base_core.py +++ b/disnake/ext/commands/base_core.py @@ -753,16 +753,14 @@ def default_member_permissions( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @overload @_generated def default_member_permissions( value: int = 0, -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @_overload_with_permissions diff --git a/disnake/ext/commands/bot.py b/disnake/ext/commands/bot.py index 1e3e2d864a..0cd80cb628 100644 --- a/disnake/ext/commands/bot.py +++ b/disnake/ext/commands/bot.py @@ -289,8 +289,7 @@ def __init__( member_cache_flags: Optional[MemberCacheFlags] = None, localization_provider: Optional[LocalizationProtocol] = None, strict_localization: bool = False, - ) -> None: - ... + ) -> None: ... class AutoShardedBot(BotBase, InteractionBotBase, disnake.AutoShardedClient): @@ -343,8 +342,7 @@ def __init__( member_cache_flags: Optional[MemberCacheFlags] = None, localization_provider: Optional[LocalizationProtocol] = None, strict_localization: bool = False, - ) -> None: - ... + ) -> None: ... class InteractionBot(InteractionBotBase, disnake.Client): @@ -516,8 +514,7 @@ def __init__( member_cache_flags: Optional[MemberCacheFlags] = None, localization_provider: Optional[LocalizationProtocol] = None, strict_localization: bool = False, - ) -> None: - ... + ) -> None: ... class AutoShardedInteractionBot(InteractionBotBase, disnake.AutoShardedClient): @@ -563,5 +560,4 @@ def __init__( member_cache_flags: Optional[MemberCacheFlags] = None, localization_provider: Optional[LocalizationProtocol] = None, strict_localization: bool = False, - ) -> None: - ... + ) -> None: ... diff --git a/disnake/ext/commands/bot_base.py b/disnake/ext/commands/bot_base.py index 1bba906c82..f663003cb8 100644 --- a/disnake/ext/commands/bot_base.py +++ b/disnake/ext/commands/bot_base.py @@ -136,8 +136,7 @@ def __init__( elif ( # note: no need to check for empty iterables, # as they won't be allowed by `get_prefix` - command_prefix is not when_mentioned - and not self.intents.message_content + command_prefix is not when_mentioned and not self.intents.message_content ): warnings.warn( "Message Content intent is not enabled and a prefix is configured. " diff --git a/disnake/ext/commands/core.py b/disnake/ext/commands/core.py index f69c367b5f..a32cfa48cc 100644 --- a/disnake/ext/commands/core.py +++ b/disnake/ext/commands/core.py @@ -975,7 +975,9 @@ def short_doc(self) -> str: return "" def _is_typing_optional(self, annotation: Union[T, Optional[T]]) -> TypeGuard[Optional[T]]: - return getattr(annotation, "__origin__", None) is Union and type(None) in annotation.__args__ # type: ignore + return ( + getattr(annotation, "__origin__", None) is Union and type(None) in annotation.__args__ # type: ignore + ) @property def signature(self) -> str: @@ -1263,8 +1265,7 @@ def command( cls: Type[CommandT], *args: Any, **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: ... @overload def command( @@ -1273,8 +1274,7 @@ def command( *args: Any, cls: Type[CommandT], **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: ... @overload def command( @@ -1282,8 +1282,7 @@ def command( name: str = ..., *args: Any, **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], Command[CogT, P, T]]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], Command[CogT, P, T]]: ... def command( self, @@ -1316,8 +1315,7 @@ def group( cls: Type[GroupT], *args: Any, **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: ... @overload def group( @@ -1326,8 +1324,7 @@ def group( *args: Any, cls: Type[GroupT], **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: ... @overload def group( @@ -1335,8 +1332,7 @@ def group( name: str = ..., *args: Any, **kwargs: Any, - ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], Group[CogT, P, T]]: - ... + ) -> Callable[[CommandCallback[CogT, ContextT, P, T]], Group[CogT, P, T]]: ... def group( self, @@ -1483,25 +1479,23 @@ class CommandDecorator(Protocol): @overload def __call__( self, func: Callable[Concatenate[ContextT, P], Coro[T]] - ) -> Command[None, P, T]: - ... + ) -> Command[None, P, T]: ... @overload def __call__( self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]] - ) -> Command[CogT, P, T]: - ... + ) -> Command[CogT, P, T]: ... class GroupDecorator(Protocol): @overload - def __call__(self, func: Callable[Concatenate[ContextT, P], Coro[T]]) -> Group[None, P, T]: - ... + def __call__( + self, func: Callable[Concatenate[ContextT, P], Coro[T]] + ) -> Group[None, P, T]: ... @overload def __call__( self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]] - ) -> Group[CogT, P, T]: - ... + ) -> Group[CogT, P, T]: ... # Small explanation regarding these overloads: @@ -1518,8 +1512,7 @@ def command( name: str, cls: Type[CommandT], **attrs: Any, -) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: - ... +) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: ... @overload @@ -1528,16 +1521,14 @@ def command( *, cls: Type[CommandT], **attrs: Any, -) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: - ... +) -> Callable[[CommandCallback[CogT, ContextT, P, T]], CommandT]: ... @overload def command( name: str = ..., **attrs: Any, -) -> CommandDecorator: - ... +) -> CommandDecorator: ... def command( @@ -1590,8 +1581,7 @@ def group( name: str, cls: Type[GroupT], **attrs: Any, -) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: - ... +) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: ... @overload @@ -1600,16 +1590,14 @@ def group( *, cls: Type[GroupT], **attrs: Any, -) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: - ... +) -> Callable[[CommandCallback[CogT, ContextT, P, T]], GroupT]: ... @overload def group( name: str = ..., **attrs: Any, -) -> GroupDecorator: - ... +) -> GroupDecorator: ... def group( @@ -2051,14 +2039,12 @@ def has_permissions( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @overload @_generated -def has_permissions() -> Callable[[T], T]: - ... +def has_permissions() -> Callable[[T], T]: ... @_overload_with_permissions @@ -2177,14 +2163,12 @@ def bot_has_permissions( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @overload @_generated -def bot_has_permissions() -> Callable[[T], T]: - ... +def bot_has_permissions() -> Callable[[T], T]: ... @_overload_with_permissions @@ -2281,14 +2265,12 @@ def has_guild_permissions( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @overload @_generated -def has_guild_permissions() -> Callable[[T], T]: - ... +def has_guild_permissions() -> Callable[[T], T]: ... @_overload_with_permissions @@ -2382,14 +2364,12 @@ def bot_has_guild_permissions( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., -) -> Callable[[T], T]: - ... +) -> Callable[[T], T]: ... @overload @_generated -def bot_has_guild_permissions() -> Callable[[T], T]: - ... +def bot_has_guild_permissions() -> Callable[[T], T]: ... @_overload_with_permissions diff --git a/disnake/ext/commands/ctx_menus_core.py b/disnake/ext/commands/ctx_menus_core.py index b7ad876424..ddabebee81 100644 --- a/disnake/ext/commands/ctx_menus_core.py +++ b/disnake/ext/commands/ctx_menus_core.py @@ -335,7 +335,7 @@ def user_command( """ def decorator( - func: InteractionCommandCallback[CogT, UserCommandInteraction, P] + func: InteractionCommandCallback[CogT, UserCommandInteraction, P], ) -> InvokableUserCommand: if not asyncio.iscoroutinefunction(func): raise TypeError(f"<{func.__qualname__}> must be a coroutine function") @@ -443,7 +443,7 @@ def message_command( """ def decorator( - func: InteractionCommandCallback[CogT, MessageCommandInteraction, P] + func: InteractionCommandCallback[CogT, MessageCommandInteraction, P], ) -> InvokableMessageCommand: if not asyncio.iscoroutinefunction(func): raise TypeError(f"<{func.__qualname__}> must be a coroutine function") diff --git a/disnake/ext/commands/flags.py b/disnake/ext/commands/flags.py index 17fe65531f..4c785e0d1d 100644 --- a/disnake/ext/commands/flags.py +++ b/disnake/ext/commands/flags.py @@ -100,13 +100,11 @@ def __init__( sync_global_commands: bool = ..., sync_guild_commands: bool = ..., sync_on_cog_actions: bool = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated - def __init__(self: NoReturn) -> None: - ... + def __init__(self: NoReturn) -> None: ... def __init__(self, **kwargs: bool) -> None: self.value = all_flags_value(self.VALID_FLAGS) diff --git a/disnake/ext/commands/help.py b/disnake/ext/commands/help.py index ecd3988b86..4bb5308547 100644 --- a/disnake/ext/commands/help.py +++ b/disnake/ext/commands/help.py @@ -952,7 +952,7 @@ def add_indented_commands(self, commands, *, heading, max_size: Optional[int] = for command in commands: name = command.name width = max_size - (get_width(name) - len(name)) - entry = f'{self.indent * " "}{name:<{width}} {command.short_doc}' + entry = f"{self.indent * ' '}{name:<{width}} {command.short_doc}" self.paginator.add_line(self.shorten_text(entry)) async def send_pages(self) -> None: @@ -1199,7 +1199,7 @@ def add_aliases_formatting(self, aliases) -> None: aliases: Sequence[:class:`str`] A list of aliases to format. """ - self.paginator.add_line(f'**{self.aliases_heading}** {", ".join(aliases)}', empty=True) + self.paginator.add_line(f"**{self.aliases_heading}** {', '.join(aliases)}", empty=True) def add_command_formatting(self, command) -> None: """A utility function to format commands and groups. diff --git a/disnake/ext/commands/interaction_bot_base.py b/disnake/ext/commands/interaction_bot_base.py index 902c2c1880..5e890448cf 100644 --- a/disnake/ext/commands/interaction_bot_base.py +++ b/disnake/ext/commands/interaction_bot_base.py @@ -694,7 +694,7 @@ def user_command( """ def decorator( - func: InteractionCommandCallback[CogT, UserCommandInteraction, P] + func: InteractionCommandCallback[CogT, UserCommandInteraction, P], ) -> InvokableUserCommand: result = user_command( name=name, @@ -797,7 +797,7 @@ def message_command( """ def decorator( - func: InteractionCommandCallback[CogT, MessageCommandInteraction, P] + func: InteractionCommandCallback[CogT, MessageCommandInteraction, P], ) -> InvokableMessageCommand: result = message_command( name=name, @@ -1262,7 +1262,7 @@ def check_app_commands(inter): message_commands = True def decorator( - func: Callable[[ApplicationCommandInteraction], Any] + func: Callable[[ApplicationCommandInteraction], Any], ) -> Callable[[ApplicationCommandInteraction], Any]: # T was used instead of Check to ensure the type matches on return self.add_app_command_check( diff --git a/disnake/ext/commands/params.py b/disnake/ext/commands/params.py index e7df5f543d..18756cd4ed 100644 --- a/disnake/ext/commands/params.py +++ b/disnake/ext/commands/params.py @@ -478,7 +478,6 @@ class ParamInfo: """ TYPES: ClassVar[Dict[type, int]] = { - # fmt: off str: OptionType.string.value, int: OptionType.integer.value, bool: OptionType.boolean.value, @@ -495,8 +494,7 @@ class ParamInfo: Union[disnake.User, disnake.Member, disnake.Role]: OptionType.mentionable.value, float: OptionType.number.value, disnake.Attachment: OptionType.attachment.value, - # fmt: on - } + } # fmt: skip _registered_converters: ClassVar[Dict[type, Callable]] = {} def __init__( @@ -675,7 +673,10 @@ async def convert_argument(self, inter: ApplicationCommandInteraction, argument: def _parse_enum(self, annotation: Any) -> None: if isinstance(annotation, (EnumMeta, disnake.enums.EnumMeta)): - self.choices = [OptionChoice(name, value.value) for name, value in annotation.__members__.items()] # type: ignore + self.choices = [ + OptionChoice(name, value.value) # type: ignore + for name, value in annotation.__members__.items() + ] else: self.choices = [OptionChoice(str(i), i) for i in annotation.__args__] diff --git a/disnake/ext/tasks/__init__.py b/disnake/ext/tasks/__init__.py index 95ff023330..f421562b15 100644 --- a/disnake/ext/tasks/__init__.py +++ b/disnake/ext/tasks/__init__.py @@ -705,11 +705,9 @@ def change_interval( class Object(Protocol[T_co, P]): - def __new__(cls) -> T_co: - ... + def __new__(cls) -> T_co: ... - def __init__(self, *args: P.args, **kwargs: P.kwargs) -> None: - ... + def __init__(self, *args: P.args, **kwargs: P.kwargs) -> None: ... @overload @@ -722,15 +720,13 @@ def loop( count: Optional[int] = None, reconnect: bool = True, loop: asyncio.AbstractEventLoop = ..., -) -> Callable[[LF], Loop[LF]]: - ... +) -> Callable[[LF], Loop[LF]]: ... @overload def loop( cls: Type[Object[L_co, Concatenate[LF, P]]], *_: P.args, **kwargs: P.kwargs -) -> Callable[[LF], L_co]: - ... +) -> Callable[[LF], L_co]: ... def loop( diff --git a/disnake/flags.py b/disnake/flags.py index 53a72c5cbf..c8434bc14a 100644 --- a/disnake/flags.py +++ b/disnake/flags.py @@ -88,12 +88,10 @@ def __invert__(self: flag_value[T]) -> T: return ~self._parent._from_value(self.flag) @overload - def __get__(self, instance: None, owner: Type[BF]) -> flag_value[BF]: - ... + def __get__(self, instance: None, owner: Type[BF]) -> flag_value[BF]: ... @overload - def __get__(self, instance: BF, owner: Type[BF]) -> bool: - ... + def __get__(self, instance: BF, owner: Type[BF]) -> bool: ... def __get__(self, instance: Optional[BF], owner: Type[BF]) -> Any: if instance is None: @@ -438,8 +436,7 @@ def __init__( premium_subscriptions: bool = ..., role_subscription_purchase_notification_replies: bool = ..., role_subscription_purchase_notifications: bool = ..., - ) -> None: - ... + ) -> None: ... # For some reason the flags for system channels are "inverted" # ergo, if they're set then it means "suppress" (off in the GUI toggle) @@ -611,8 +608,7 @@ def __init__( suppress_embeds: bool = ..., suppress_notifications: bool = ..., urgent: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def crossposted(self): @@ -820,8 +816,7 @@ def __init__( team_user: bool = ..., verified_bot: bool = ..., verified_bot_developer: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def staff(self): @@ -1079,13 +1074,11 @@ def __init__( typing: bool = ..., voice_states: bool = ..., webhooks: bool = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated - def __init__(self: NoReturn) -> None: - ... + def __init__(self: NoReturn) -> None: ... def __init__(self, value: Optional[int] = None, **kwargs: bool) -> None: if value is not None: @@ -1808,13 +1801,11 @@ class MemberCacheFlags(BaseFlags): @overload @_generated - def __init__(self, *, joined: bool = ..., voice: bool = ...) -> None: - ... + def __init__(self, *, joined: bool = ..., voice: bool = ...) -> None: ... @overload @_generated - def __init__(self: NoReturn) -> None: - ... + def __init__(self: NoReturn) -> None: ... def __init__(self, **kwargs: bool) -> None: self.value = all_flags_value(self.VALID_FLAGS) @@ -2001,8 +1992,7 @@ def __init__( gateway_presence: bool = ..., gateway_presence_limited: bool = ..., verification_pending_guild_limit: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def application_auto_moderation_rule_create_badge(self): @@ -2169,8 +2159,7 @@ def __init__( hide_media_download_options: bool = ..., pinned: bool = ..., require_tag: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def pinned(self): @@ -2275,8 +2264,7 @@ class AutoModKeywordPresets(ListBaseFlags): @_generated def __init__( self, *, profanity: bool = ..., sexual_content: bool = ..., slurs: bool = ... - ) -> None: - ... + ) -> None: ... @classmethod def all(cls) -> Self: @@ -2397,8 +2385,7 @@ def __init__( is_guest: bool = ..., started_home_actions: bool = ..., started_onboarding: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def did_rejoin(self): @@ -2532,8 +2519,7 @@ class RoleFlags(BaseFlags): if TYPE_CHECKING: @_generated - def __init__(self, *, in_prompt: bool = ...) -> None: - ... + def __init__(self, *, in_prompt: bool = ...) -> None: ... @flag_value def in_prompt(self): @@ -2612,8 +2598,7 @@ class AttachmentFlags(BaseFlags): if TYPE_CHECKING: @_generated - def __init__(self, *, is_remix: bool = ...) -> None: - ... + def __init__(self, *, is_remix: bool = ...) -> None: ... @flag_value def is_remix(self): @@ -2698,8 +2683,7 @@ def __init__( available: bool = ..., guild_subscription: bool = ..., user_subscription: bool = ..., - ) -> None: - ... + ) -> None: ... @flag_value def available(self): @@ -2790,8 +2774,7 @@ class ApplicationInstallTypes(ListBaseFlags): if TYPE_CHECKING: @_generated - def __init__(self, *, guild: bool = ..., user: bool = ...) -> None: - ... + def __init__(self, *, guild: bool = ..., user: bool = ...) -> None: ... @classmethod def all(cls) -> Self: @@ -2886,8 +2869,7 @@ class InteractionContextTypes(ListBaseFlags): @_generated def __init__( self, *, bot_dm: bool = ..., guild: bool = ..., private_channel: bool = ... - ) -> None: - ... + ) -> None: ... @classmethod def all(cls) -> Self: diff --git a/disnake/gateway.py b/disnake/gateway.py index ef54d5580b..a9de180a94 100644 --- a/disnake/gateway.py +++ b/disnake/gateway.py @@ -62,22 +62,18 @@ T = TypeVar("T") class DispatchFunc(Protocol): - def __call__(self, event: str, *args: Any) -> None: - ... + def __call__(self, event: str, *args: Any) -> None: ... class GatewayErrorFunc(Protocol): async def __call__( self, event: str, data: Any, shard_id: Optional[int], exc: Exception, / - ) -> None: - ... + ) -> None: ... class CallHooksFunc(Protocol): - async def __call__(self, key: str, *args: Any, **kwargs: Any) -> None: - ... + async def __call__(self, key: str, *args: Any, **kwargs: Any) -> None: ... class HookFunc(Protocol): - async def __call__(self, *args: Any) -> None: - ... + async def __call__(self, *args: Any) -> None: ... _log = logging.getLogger(__name__) @@ -280,14 +276,11 @@ class HeartbeatWebSocket(Protocol): loop: asyncio.AbstractEventLoop _max_heartbeat_timeout: float - async def close(self, code: int) -> None: - ... + async def close(self, code: int) -> None: ... - async def send_heartbeat(self, data: HeartbeatCommand) -> None: - ... + async def send_heartbeat(self, data: HeartbeatCommand) -> None: ... - def get_heartbeat_data(self) -> Optional[int]: - ... + def get_heartbeat_data(self) -> Optional[int]: ... class DiscordWebSocket: diff --git a/disnake/guild.py b/disnake/guild.py index 1b436e4625..8eea1807e2 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -623,7 +623,9 @@ def _from_data(self, guild: GuildPayload) -> None: self._large: Optional[bool] = None if member_count is None else self._member_count >= 250 self.owner_id: Optional[int] = utils._get_as_snowflake(guild, "owner_id") - self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, "afk_channel_id")) # type: ignore + self.afk_channel: Optional[VocalGuildChannel] = self.get_channel( + utils._get_as_snowflake(guild, "afk_channel_id") # type: ignore + ) for obj in guild.get("voice_states", []): self._update_voice_state(obj, utils._get_as_snowflake(obj, "channel_id")) @@ -2495,8 +2497,7 @@ async def create_scheduled_event( description: str = ..., image: AssetBytes = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... @overload async def create_scheduled_event( @@ -2514,8 +2515,7 @@ async def create_scheduled_event( description: str = ..., image: AssetBytes = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... @overload async def create_scheduled_event( @@ -2531,8 +2531,7 @@ async def create_scheduled_event( description: str = ..., image: AssetBytes = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... async def create_scheduled_event( self, @@ -3661,12 +3660,10 @@ async def fetch_roles(self) -> List[Role]: @overload async def get_or_fetch_member( self, member_id: int, *, strict: Literal[False] = ... - ) -> Optional[Member]: - ... + ) -> Optional[Member]: ... @overload - async def get_or_fetch_member(self, member_id: int, *, strict: Literal[True]) -> Member: - ... + async def get_or_fetch_member(self, member_id: int, *, strict: Literal[True]) -> Member: ... async def get_or_fetch_member( self, member_id: int, *, strict: bool = False @@ -3721,8 +3718,7 @@ async def create_role( icon: AssetBytes = ..., emoji: str = ..., mentionable: bool = ..., - ) -> Role: - ... + ) -> Role: ... @overload async def create_role( @@ -3736,8 +3732,7 @@ async def create_role( icon: AssetBytes = ..., emoji: str = ..., mentionable: bool = ..., - ) -> Role: - ... + ) -> Role: ... async def create_role( self, @@ -3943,8 +3938,7 @@ async def ban( *, clean_history_duration: Union[int, datetime.timedelta] = 86400, reason: Optional[str] = None, - ) -> None: - ... + ) -> None: ... @overload async def ban( @@ -3953,8 +3947,7 @@ async def ban( *, delete_message_days: Literal[0, 1, 2, 3, 4, 5, 6, 7] = 1, reason: Optional[str] = None, - ) -> None: - ... + ) -> None: ... async def ban( self, @@ -4799,8 +4792,7 @@ async def timeout( *, duration: Optional[Union[float, datetime.timedelta]], reason: Optional[str] = None, - ) -> Member: - ... + ) -> Member: ... @overload async def timeout( @@ -4809,8 +4801,7 @@ async def timeout( *, until: Optional[datetime.datetime], reason: Optional[str] = None, - ) -> Member: - ... + ) -> Member: ... async def timeout( self, diff --git a/disnake/guild_scheduled_event.py b/disnake/guild_scheduled_event.py index 1b01be136c..27bded9ff5 100644 --- a/disnake/guild_scheduled_event.py +++ b/disnake/guild_scheduled_event.py @@ -285,8 +285,7 @@ async def edit( entity_metadata: Optional[GuildScheduledEventMetadata] = ..., status: GuildScheduledEventStatus = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... # new entity_type is `external`, no channel @overload @@ -304,8 +303,7 @@ async def edit( entity_metadata: GuildScheduledEventMetadata = ..., status: GuildScheduledEventStatus = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... # new entity_type is `voice` or `stage_instance`, no entity_metadata @overload @@ -325,8 +323,7 @@ async def edit( scheduled_end_time: Optional[datetime] = ..., status: GuildScheduledEventStatus = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... # channel=None, no entity_type @overload @@ -343,8 +340,7 @@ async def edit( entity_metadata: GuildScheduledEventMetadata = ..., status: GuildScheduledEventStatus = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... # valid channel, no entity_type @overload @@ -360,8 +356,7 @@ async def edit( scheduled_end_time: Optional[datetime] = ..., status: GuildScheduledEventStatus = ..., reason: Optional[str] = ..., - ) -> GuildScheduledEvent: - ... + ) -> GuildScheduledEvent: ... async def edit( self, diff --git a/disnake/i18n.py b/disnake/i18n.py index 9a9ca32560..fef3d85315 100644 --- a/disnake/i18n.py +++ b/disnake/i18n.py @@ -87,12 +87,10 @@ class Localized(Generic[StringT]): __slots__ = ("string", "localizations") @overload - def __init__(self: Localized[StringT], string: StringT, *, key: str) -> None: - ... + def __init__(self: Localized[StringT], string: StringT, *, key: str) -> None: ... @overload - def __init__(self: Localized[Optional[str]], *, key: str) -> None: - ... + def __init__(self: Localized[Optional[str]], *, key: str) -> None: ... @overload def __init__( @@ -100,16 +98,14 @@ def __init__( string: StringT, *, data: Union[Optional[LocalizationsDict], LocalizationValue], - ) -> None: - ... + ) -> None: ... @overload def __init__( self: Localized[Optional[str]], *, data: Union[Optional[LocalizationsDict], LocalizationValue], - ) -> None: - ... + ) -> None: ... # note: `data` accepting `LocalizationValue` is intentionally undocumented, # as it's only meant to be used internally @@ -131,13 +127,13 @@ def __init__( @overload @classmethod - def _cast(cls, string: LocalizedOptional, required: Literal[False]) -> Localized[Optional[str]]: - ... + def _cast( + cls, string: LocalizedOptional, required: Literal[False] + ) -> Localized[Optional[str]]: ... @overload @classmethod - def _cast(cls, string: LocalizedRequired, required: Literal[True]) -> Localized[str]: - ... + def _cast(cls, string: LocalizedRequired, required: Literal[True]) -> Localized[str]: ... @classmethod def _cast(cls, string: Union[Optional[str], Localized[Any]], required: bool) -> Localized[Any]: @@ -150,12 +146,10 @@ def _cast(cls, string: Union[Optional[str], Localized[Any]], required: bool) -> return string @overload - def _upgrade(self, *, key: Optional[str]) -> Self: - ... + def _upgrade(self, *, key: Optional[str]) -> Self: ... @overload - def _upgrade(self, string: str, *, key: Optional[str] = None) -> Localized[str]: - ... + def _upgrade(self, string: str, *, key: Optional[str] = None) -> Localized[str]: ... def _upgrade( self: Localized[Any], string: Optional[str] = None, *, key: Optional[str] = None diff --git a/disnake/integrations.py b/disnake/integrations.py index 526da5d49f..0bd92a762c 100644 --- a/disnake/integrations.py +++ b/disnake/integrations.py @@ -418,10 +418,7 @@ def _from_data(self, data: BotIntegrationPayload) -> None: self.scopes: List[str] = data.get("scopes") or [] def __repr__(self) -> str: - return ( - f"<{self.__class__.__name__} id={self.id}" - f" name={self.name!r} scopes={self.scopes!r}>" - ) + return f"<{self.__class__.__name__} id={self.id} name={self.name!r} scopes={self.scopes!r}>" def _integration_factory(value: str) -> Tuple[Type[Integration], str]: diff --git a/disnake/interactions/base.py b/disnake/interactions/base.py index eb28fec4eb..12a9e988d6 100644 --- a/disnake/interactions/base.py +++ b/disnake/interactions/base.py @@ -1385,8 +1385,7 @@ async def autocomplete(self, *, choices: Choices) -> None: self._response_type = response_type @overload - async def send_modal(self, modal: Modal) -> None: - ... + async def send_modal(self, modal: Modal) -> None: ... @overload async def send_modal( @@ -1395,8 +1394,7 @@ async def send_modal( title: str, custom_id: str, components: Components[ModalUIComponent], - ) -> None: - ... + ) -> None: ... async def send_modal( self, @@ -1644,8 +1642,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> InteractionMessage: - ... + ) -> InteractionMessage: ... @overload async def edit( @@ -1661,8 +1658,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> InteractionMessage: - ... + ) -> InteractionMessage: ... @overload async def edit( @@ -1678,8 +1674,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> InteractionMessage: - ... + ) -> InteractionMessage: ... @overload async def edit( @@ -1695,8 +1690,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> InteractionMessage: - ... + ) -> InteractionMessage: ... async def edit( self, @@ -2007,14 +2001,12 @@ def __repr__(self) -> str: @overload def get_with_type( self, key: Snowflake, data_type: Union[OptionType, ComponentType] - ) -> Union[Member, User, Role, AnyChannel, Message, Attachment, None]: - ... + ) -> Union[Member, User, Role, AnyChannel, Message, Attachment, None]: ... @overload def get_with_type( self, key: Snowflake, data_type: Union[OptionType, ComponentType], default: T - ) -> Union[Member, User, Role, AnyChannel, Message, Attachment, T]: - ... + ) -> Union[Member, User, Role, AnyChannel, Message, Attachment, T]: ... def get_with_type( self, key: Snowflake, data_type: Union[OptionType, ComponentType], default: T = None diff --git a/disnake/invite.py b/disnake/invite.py index 545159dfb8..8dd058b4cc 100644 --- a/disnake/invite.py +++ b/disnake/invite.py @@ -435,7 +435,9 @@ def __init__( ) inviter_data = data.get("inviter") - self.inviter: Optional[User] = None if inviter_data is None else self._state.create_user(inviter_data) # type: ignore + self.inviter: Optional[User] = ( + None if inviter_data is None else self._state.create_user(inviter_data) # type: ignore + ) self.channel: Optional[InviteChannelType] = self._resolve_channel( data.get("channel"), channel @@ -457,7 +459,9 @@ def __init__( self.guild_welcome_screen: Optional[WelcomeScreen] = None target_user_data = data.get("target_user") - self.target_user: Optional[User] = None if target_user_data is None else self._state.create_user(target_user_data) # type: ignore + self.target_user: Optional[User] = ( + None if target_user_data is None else self._state.create_user(target_user_data) # type: ignore + ) self.target_type: InviteTarget = try_enum(InviteTarget, data.get("target_type", 0)) diff --git a/disnake/member.py b/disnake/member.py index c8484bb9e7..7ceec7967a 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -303,8 +303,7 @@ def __init__( data: Union[MemberWithUserPayload, GuildMemberUpdateEvent], guild: Guild, state: ConnectionState, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -314,8 +313,7 @@ def __init__( guild: Guild, state: ConnectionState, user_data: UserPayload, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -455,7 +453,8 @@ def _presence_update( ) -> Optional[Tuple[User, User]]: self.activities = tuple(create_activity(a, state=self._state) for a in data["activities"]) self._client_status = { - sys.intern(key): sys.intern(value) for key, value in data.get("client_status", {}).items() # type: ignore + sys.intern(key): sys.intern(value) # type: ignore + for key, value in data.get("client_status", {}).items() } self._client_status[None] = sys.intern(data["status"]) @@ -810,8 +809,7 @@ async def ban( *, clean_history_duration: Union[int, datetime.timedelta] = 86400, reason: Optional[str] = None, - ) -> None: - ... + ) -> None: ... @overload async def ban( @@ -819,8 +817,7 @@ async def ban( *, delete_message_days: Literal[0, 1, 2, 3, 4, 5, 6, 7] = 1, reason: Optional[str] = None, - ) -> None: - ... + ) -> None: ... async def ban( self, @@ -1194,8 +1191,7 @@ async def timeout( *, duration: Optional[Union[float, datetime.timedelta]], reason: Optional[str] = None, - ) -> Member: - ... + ) -> Member: ... @overload async def timeout( @@ -1203,8 +1199,7 @@ async def timeout( *, until: Optional[datetime.datetime], reason: Optional[str] = None, - ) -> Member: - ... + ) -> Member: ... async def timeout( self, diff --git a/disnake/message.py b/disnake/message.py index 72134988bc..9dcbdfe16b 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -1868,8 +1868,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -1885,8 +1884,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -1902,8 +1900,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -1919,8 +1916,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... async def edit( self, @@ -2635,8 +2631,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -2652,8 +2647,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -2669,8 +2663,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... @overload async def edit( @@ -2686,8 +2679,7 @@ async def edit( view: Optional[View] = ..., components: Optional[Components[MessageUIComponent]] = ..., delete_after: Optional[float] = ..., - ) -> Message: - ... + ) -> Message: ... async def edit( self, diff --git a/disnake/opus.py b/disnake/opus.py index 86a3ccbb70..b336c0cdc9 100644 --- a/disnake/opus.py +++ b/disnake/opus.py @@ -371,7 +371,7 @@ def set_bitrate(self, kbps: int) -> int: def set_bandwidth(self, req: BAND_CTL) -> None: if req not in band_ctl: raise KeyError( - f'{req!r} is not a valid bandwidth setting. Try one of: {",".join(band_ctl)}' + f"{req!r} is not a valid bandwidth setting. Try one of: {','.join(band_ctl)}" ) k = band_ctl[req] @@ -380,7 +380,7 @@ def set_bandwidth(self, req: BAND_CTL) -> None: def set_signal_type(self, req: SIGNAL_CTL) -> None: if req not in signal_ctl: raise KeyError( - f'{req!r} is not a valid bandwidth setting. Try one of: {",".join(signal_ctl)}' + f"{req!r} is not a valid bandwidth setting. Try one of: {','.join(signal_ctl)}" ) k = signal_ctl[req] @@ -462,12 +462,10 @@ def _get_last_packet_duration(self) -> int: return ret.value @overload - def decode(self, data: bytes, *, fec: bool) -> bytes: - ... + def decode(self, data: bytes, *, fec: bool) -> bytes: ... @overload - def decode(self, data: Literal[None], *, fec: Literal[False]) -> bytes: - ... + def decode(self, data: Literal[None], *, fec: Literal[False]) -> bytes: ... def decode(self, data: Optional[bytes], *, fec: bool = False) -> bytes: if data is None and fec: diff --git a/disnake/partial_emoji.py b/disnake/partial_emoji.py index 92656bb314..167fb6589e 100644 --- a/disnake/partial_emoji.py +++ b/disnake/partial_emoji.py @@ -254,7 +254,7 @@ async def read(self) -> bytes: # (e.g. default reaction, tag emoji) @staticmethod def _emoji_to_name_id( - emoji: Optional[Union[str, Emoji, PartialEmoji]] + emoji: Optional[Union[str, Emoji, PartialEmoji]], ) -> Tuple[Optional[str], Optional[int]]: if emoji is None: return None, None diff --git a/disnake/permissions.py b/disnake/permissions.py index 95a6792fe8..771a4367ac 100644 --- a/disnake/permissions.py +++ b/disnake/permissions.py @@ -216,16 +216,14 @@ def __init__( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated def __init__( self, permissions: int = 0, - ) -> None: - ... + ) -> None: ... @_overload_with_permissions def __init__(self, permissions: int = 0, **kwargs: bool) -> None: @@ -620,15 +618,13 @@ def update( view_channel: bool = ..., view_creator_monetization_analytics: bool = ..., view_guild_insights: bool = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated def update( self, - ) -> None: - ... + ) -> None: ... @_overload_with_permissions def update(self, **kwargs: bool) -> None: @@ -1273,15 +1269,13 @@ def __init__( view_channel: Optional[bool] = ..., view_creator_monetization_analytics: Optional[bool] = ..., view_guild_insights: Optional[bool] = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated def __init__( self, - ) -> None: - ... + ) -> None: ... @_overload_with_permissions def __init__(self, **kwargs: Optional[bool]) -> None: @@ -1408,15 +1402,13 @@ def update( view_channel: Optional[bool] = ..., view_creator_monetization_analytics: Optional[bool] = ..., view_guild_insights: Optional[bool] = ..., - ) -> None: - ... + ) -> None: ... @overload @_generated def update( self, - ) -> None: - ... + ) -> None: ... @_overload_with_permissions def update(self, **kwargs: Optional[bool]) -> None: diff --git a/disnake/player.py b/disnake/player.py index 1eaf0d45a7..9a99946082 100644 --- a/disnake/player.py +++ b/disnake/player.py @@ -557,8 +557,7 @@ async def probe( fallback = cls._probe_codec_fallback else: raise TypeError( - "Expected str or callable for parameter 'probe', " - f"not '{method.__class__.__name__}'" + f"Expected str or callable for parameter 'probe', not '{method.__class__.__name__}'" ) codec = bitrate = None diff --git a/disnake/shard.py b/disnake/shard.py index 3903d413aa..4ad92b5779 100644 --- a/disnake/shard.py +++ b/disnake/shard.py @@ -369,12 +369,10 @@ def __init__( member_cache_flags: Optional[MemberCacheFlags] = None, localization_provider: Optional[LocalizationProtocol] = None, strict_localization: bool = False, - ) -> None: - ... + ) -> None: ... @overload - def __init__(self: NoReturn) -> None: - ... + def __init__(self: NoReturn) -> None: ... def __init__(self, *args: Any, shard_ids: Optional[List[int]] = None, **kwargs: Any) -> None: self.shard_ids = shard_ids diff --git a/disnake/state.py b/disnake/state.py index 0c1f7238da..eb2b9fbfcb 100644 --- a/disnake/state.py +++ b/disnake/state.py @@ -1447,14 +1447,12 @@ def is_guild_evicted(self, guild) -> bool: @overload async def chunk_guild( self, guild: Guild, *, wait: Literal[False], cache: Optional[bool] = None - ) -> asyncio.Future[List[Member]]: - ... + ) -> asyncio.Future[List[Member]]: ... @overload async def chunk_guild( self, guild: Guild, *, wait: Literal[True] = True, cache: Optional[bool] = None - ) -> List[Member]: - ... + ) -> List[Member]: ... async def chunk_guild( self, guild: Guild, *, wait: bool = True, cache: Optional[bool] = None @@ -2192,8 +2190,7 @@ def _get_partial_interaction_channel( guild: Optional[Union[Guild, Object]], *, return_messageable: Literal[False] = False, - ) -> AnyChannel: - ... + ) -> AnyChannel: ... @overload def _get_partial_interaction_channel( @@ -2202,8 +2199,7 @@ def _get_partial_interaction_channel( guild: Optional[Union[Guild, Object]], *, return_messageable: Literal[True], - ) -> MessageableChannel: - ... + ) -> MessageableChannel: ... # note: this resolves unknown types to `PartialMessageable` def _get_partial_interaction_channel( @@ -2273,7 +2269,10 @@ async def fetch_global_commands( *, with_localizations: bool = True, ) -> List[APIApplicationCommand]: - results = await self.http.get_global_commands(self.application_id, with_localizations=with_localizations) # type: ignore + results = await self.http.get_global_commands( + self.application_id, # type: ignore + with_localizations=with_localizations, + ) return [application_command_factory(data) for data in results] async def fetch_global_command(self, command_id: int) -> APIApplicationCommand: @@ -2284,7 +2283,8 @@ async def create_global_command( self, application_command: ApplicationCommand ) -> APIApplicationCommand: result = await self.http.upsert_global_command( - self.application_id, application_command.to_dict() # type: ignore + self.application_id, # type: ignore + application_command.to_dict(), ) cmd = application_command_factory(result) self._add_global_application_command(cmd) @@ -2294,7 +2294,9 @@ async def edit_global_command( self, command_id: int, new_command: ApplicationCommand ) -> APIApplicationCommand: result = await self.http.edit_global_command( - self.application_id, command_id, new_command.to_dict() # type: ignore + self.application_id, # type: ignore + command_id, + new_command.to_dict(), ) cmd = application_command_factory(result) self._add_global_application_command(cmd) @@ -2321,7 +2323,11 @@ async def fetch_guild_commands( *, with_localizations: bool = True, ) -> List[APIApplicationCommand]: - results = await self.http.get_guild_commands(self.application_id, guild_id, with_localizations=with_localizations) # type: ignore + results = await self.http.get_guild_commands( + self.application_id, # type: ignore + guild_id, + with_localizations=with_localizations, + ) return [application_command_factory(data) for data in results] async def fetch_guild_command(self, guild_id: int, command_id: int) -> APIApplicationCommand: @@ -2332,7 +2338,9 @@ async def create_guild_command( self, guild_id: int, application_command: ApplicationCommand ) -> APIApplicationCommand: result = await self.http.upsert_guild_command( - self.application_id, guild_id, application_command.to_dict() # type: ignore + self.application_id, # type: ignore + guild_id, + application_command.to_dict(), ) cmd = application_command_factory(result) self._add_guild_application_command(guild_id, cmd) @@ -2342,7 +2350,10 @@ async def edit_guild_command( self, guild_id: int, command_id: int, new_command: ApplicationCommand ) -> APIApplicationCommand: result = await self.http.edit_guild_command( - self.application_id, guild_id, command_id, new_command.to_dict() # type: ignore + self.application_id, # type: ignore + guild_id, + command_id, + new_command.to_dict(), ) cmd = application_command_factory(result) self._add_guild_application_command(guild_id, cmd) @@ -2350,7 +2361,9 @@ async def edit_guild_command( async def delete_guild_command(self, guild_id: int, command_id: int) -> None: await self.http.delete_guild_command( - self.application_id, guild_id, command_id # type: ignore + self.application_id, # type: ignore + guild_id, + command_id, ) self._remove_guild_application_command(guild_id, command_id) @@ -2359,7 +2372,9 @@ async def bulk_overwrite_guild_commands( ) -> List[APIApplicationCommand]: payload = [cmd.to_dict() for cmd in application_commands] results = await self.http.bulk_upsert_guild_commands( - self.application_id, guild_id, payload # type: ignore + self.application_id, # type: ignore + guild_id, + payload, ) commands = [application_command_factory(data) for data in results] self._guild_application_commands[guild_id] = {cmd.id: cmd for cmd in commands} @@ -2371,7 +2386,8 @@ async def bulk_fetch_command_permissions( self, guild_id: int ) -> List[GuildApplicationCommandPermissions]: array = await self.http.get_guild_application_command_permissions( - self.application_id, guild_id # type: ignore + self.application_id, # type: ignore + guild_id, ) return [GuildApplicationCommandPermissions(state=self, data=obj) for obj in array] @@ -2379,7 +2395,9 @@ async def fetch_command_permissions( self, guild_id: int, command_id: int ) -> GuildApplicationCommandPermissions: data = await self.http.get_application_command_permissions( - self.application_id, guild_id, command_id # type: ignore + self.application_id, # type: ignore + guild_id, + command_id, ) return GuildApplicationCommandPermissions(state=self, data=data) diff --git a/disnake/sticker.py b/disnake/sticker.py index 322d12485d..58303c2162 100644 --- a/disnake/sticker.py +++ b/disnake/sticker.py @@ -508,7 +508,7 @@ async def delete(self, *, reason: Optional[str] = None) -> None: def _sticker_factory( - sticker_type: Literal[1, 2] + sticker_type: Literal[1, 2], ) -> Tuple[Type[Union[StandardSticker, GuildSticker, Sticker]], StickerType]: value = try_enum(StickerType, sticker_type) if value == StickerType.standard: diff --git a/disnake/types/activity.py b/disnake/types/activity.py index 811c9a7144..39a292f46a 100644 --- a/disnake/types/activity.py +++ b/disnake/types/activity.py @@ -70,7 +70,8 @@ class SendableActivity(TypedDict): class Activity(SendableActivity, total=False): - created_at: int # required according to docs, but we treat it as optional for easier serialization + # `created_at` is required according to docs, but we treat it as optional for easier serialization + created_at: int timestamps: ActivityTimestamps application_id: Snowflake details: Optional[str] diff --git a/disnake/types/gateway.py b/disnake/types/gateway.py index 0aabbbf47c..2c6df4ea00 100644 --- a/disnake/types/gateway.py +++ b/disnake/types/gateway.py @@ -259,8 +259,7 @@ class ReadyEvent(TypedDict): # https://discord.com/developers/docs/topics/gateway-events#resumed -class ResumedEvent(TypedDict): - ... +class ResumedEvent(TypedDict): ... # https://discord.com/developers/docs/topics/gateway-events#application-command-permissions-update @@ -305,8 +304,7 @@ class MessageReactionAddEvent(_BaseReactionEvent): # https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove -class MessageReactionRemoveEvent(_BaseReactionEvent): - ... +class MessageReactionRemoveEvent(_BaseReactionEvent): ... # https://discord.com/developers/docs/topics/gateway-events#message-reaction-remove-all diff --git a/disnake/ui/__init__.py b/disnake/ui/__init__.py index 273ee9e72c..90dfa57aaa 100644 --- a/disnake/ui/__init__.py +++ b/disnake/ui/__init__.py @@ -9,6 +9,7 @@ :license: MIT, see LICENSE for more details. """ + from .action_row import * from .button import * from .item import * diff --git a/disnake/ui/action_row.py b/disnake/ui/action_row.py index 8c5bf769ea..e0424fdca4 100644 --- a/disnake/ui/action_row.py +++ b/disnake/ui/action_row.py @@ -142,8 +142,7 @@ class ActionRow(Generic[UIComponentT]): # When unspecified and called empty, default to an ActionRow that takes any kind of component. @overload - def __init__(self: ActionRow[WrappedComponent]) -> None: - ... + def __init__(self: ActionRow[WrappedComponent]) -> None: ... # Explicit definitions are needed to make # "ActionRow(StringSelect(), TextInput())" and @@ -151,18 +150,15 @@ def __init__(self: ActionRow[WrappedComponent]) -> None: # differentiate themselves properly. @overload - def __init__(self: ActionRow[MessageUIComponent], *components: MessageUIComponent) -> None: - ... + def __init__(self: ActionRow[MessageUIComponent], *components: MessageUIComponent) -> None: ... @overload - def __init__(self: ActionRow[ModalUIComponent], *components: ModalUIComponent) -> None: - ... + def __init__(self: ActionRow[ModalUIComponent], *components: ModalUIComponent) -> None: ... # Allow use of "ActionRow[StrictUIComponent]" externally. @overload - def __init__(self: ActionRow[StrictUIComponentT], *components: StrictUIComponentT) -> None: - ... + def __init__(self: ActionRow[StrictUIComponentT], *components: StrictUIComponentT) -> None: ... # n.b. this should be `*components: UIComponentT`, but pyright does not like it def __init__(self, *components: Union[MessageUIComponent, ModalUIComponent]) -> None: @@ -725,12 +721,10 @@ def __delitem__(self, index: Union[int, slice]) -> None: del self._children[index] @overload - def __getitem__(self, index: int) -> UIComponentT: - ... + def __getitem__(self, index: int) -> UIComponentT: ... @overload - def __getitem__(self, index: slice) -> Sequence[UIComponentT]: - ... + def __getitem__(self, index: slice) -> Sequence[UIComponentT]: ... def __getitem__(self, index: Union[int, slice]) -> Union[UIComponentT, Sequence[UIComponentT]]: return self._children[index] diff --git a/disnake/ui/button.py b/disnake/ui/button.py index bfcccb663f..7a6e819413 100644 --- a/disnake/ui/button.py +++ b/disnake/ui/button.py @@ -92,8 +92,7 @@ def __init__( url: Optional[str] = None, emoji: Optional[Union[str, Emoji, PartialEmoji]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -106,8 +105,7 @@ def __init__( url: Optional[str] = None, emoji: Optional[Union[str, Emoji, PartialEmoji]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -261,15 +259,13 @@ def button( style: ButtonStyle = ButtonStyle.secondary, emoji: Optional[Union[str, Emoji, PartialEmoji]] = None, row: Optional[int] = None, -) -> Callable[[ItemCallbackType[V_co, Button[V_co]]], DecoratedItem[Button[V_co]]]: - ... +) -> Callable[[ItemCallbackType[V_co, Button[V_co]]], DecoratedItem[Button[V_co]]]: ... @overload def button( cls: Callable[P, B_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, B_co]], DecoratedItem[B_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, B_co]], DecoratedItem[B_co]]: ... def button( diff --git a/disnake/ui/item.py b/disnake/ui/item.py index 284e839378..927b1e0d98 100644 --- a/disnake/ui/item.py +++ b/disnake/ui/item.py @@ -56,13 +56,11 @@ class WrappedComponent(ABC): @property @abstractmethod - def _underlying(self) -> NestedComponent: - ... + def _underlying(self) -> NestedComponent: ... @property @abstractmethod - def width(self) -> int: - ... + def width(self) -> int: ... def __repr__(self) -> str: attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_attributes__) @@ -93,12 +91,10 @@ class Item(WrappedComponent, Generic[V_co]): __repr_attributes__: Tuple[str, ...] = ("row",) @overload - def __init__(self: Item[None]) -> None: - ... + def __init__(self: Item[None]) -> None: ... @overload - def __init__(self: Item[V_co]) -> None: - ... + def __init__(self: Item[V_co]) -> None: ... def __init__(self) -> None: self._view: V_co = None # type: ignore @@ -169,9 +165,7 @@ async def callback(self, interaction: MessageInteraction[ClientT], /) -> None: # which work as `View.__init__` replaces the handler with the item. class DecoratedItem(Protocol[I]): @overload - def __get__(self, obj: None, objtype: Type[SelfViewT]) -> ItemCallbackType[SelfViewT, I]: - ... + def __get__(self, obj: None, objtype: Type[SelfViewT]) -> ItemCallbackType[SelfViewT, I]: ... @overload - def __get__(self, obj: Any, objtype: Any) -> I: - ... + def __get__(self, obj: Any, objtype: Any) -> I: ... diff --git a/disnake/ui/select/__init__.py b/disnake/ui/select/__init__.py index 12a543cf27..2b4432038f 100644 --- a/disnake/ui/select/__init__.py +++ b/disnake/ui/select/__init__.py @@ -9,6 +9,7 @@ :license: MIT, see LICENSE for more details. """ + from . import base, channel, mentionable, role, string, user from .base import * from .channel import * diff --git a/disnake/ui/select/channel.py b/disnake/ui/select/channel.py index f27c7a2107..743ee0acfa 100644 --- a/disnake/ui/select/channel.py +++ b/disnake/ui/select/channel.py @@ -111,8 +111,7 @@ def __init__( channel_types: Optional[List[ChannelType]] = None, default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -126,8 +125,7 @@ def __init__( channel_types: Optional[List[ChannelType]] = None, default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -197,15 +195,15 @@ def channel_select( channel_types: Optional[List[ChannelType]] = None, default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None, row: Optional[int] = None, -) -> Callable[[ItemCallbackType[V_co, ChannelSelect[V_co]]], DecoratedItem[ChannelSelect[V_co]]]: - ... +) -> Callable[ + [ItemCallbackType[V_co, ChannelSelect[V_co]]], DecoratedItem[ChannelSelect[V_co]] +]: ... @overload def channel_select( cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ... def channel_select( diff --git a/disnake/ui/select/mentionable.py b/disnake/ui/select/mentionable.py index 1cc0be5b8a..24f2237472 100644 --- a/disnake/ui/select/mentionable.py +++ b/disnake/ui/select/mentionable.py @@ -102,8 +102,7 @@ def __init__( Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]] ] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -118,8 +117,7 @@ def __init__( Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]] ] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -176,15 +174,13 @@ def mentionable_select( row: Optional[int] = None, ) -> Callable[ [ItemCallbackType[V_co, MentionableSelect[V_co]]], DecoratedItem[MentionableSelect[V_co]] -]: - ... +]: ... @overload def mentionable_select( cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ... def mentionable_select( diff --git a/disnake/ui/select/role.py b/disnake/ui/select/role.py index 439749a136..ed81870bcc 100644 --- a/disnake/ui/select/role.py +++ b/disnake/ui/select/role.py @@ -95,8 +95,7 @@ def __init__( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -109,8 +108,7 @@ def __init__( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -161,15 +159,13 @@ def role_select( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None, row: Optional[int] = None, -) -> Callable[[ItemCallbackType[V_co, RoleSelect[V_co]]], DecoratedItem[RoleSelect[V_co]]]: - ... +) -> Callable[[ItemCallbackType[V_co, RoleSelect[V_co]]], DecoratedItem[RoleSelect[V_co]]]: ... @overload def role_select( cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ... def role_select( diff --git a/disnake/ui/select/string.py b/disnake/ui/select/string.py index b336dfa388..ae97a19aa4 100644 --- a/disnake/ui/select/string.py +++ b/disnake/ui/select/string.py @@ -117,8 +117,7 @@ def __init__( options: SelectOptionInput = ..., disabled: bool = False, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -131,8 +130,7 @@ def __init__( options: SelectOptionInput = ..., disabled: bool = False, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -265,15 +263,13 @@ def string_select( options: SelectOptionInput = ..., disabled: bool = False, row: Optional[int] = None, -) -> Callable[[ItemCallbackType[V_co, StringSelect[V_co]]], DecoratedItem[StringSelect[V_co]]]: - ... +) -> Callable[[ItemCallbackType[V_co, StringSelect[V_co]]], DecoratedItem[StringSelect[V_co]]]: ... @overload def string_select( cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ... def string_select( diff --git a/disnake/ui/select/user.py b/disnake/ui/select/user.py index 2dd20d40f6..1e69a91739 100644 --- a/disnake/ui/select/user.py +++ b/disnake/ui/select/user.py @@ -97,8 +97,7 @@ def __init__( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... @overload def __init__( @@ -111,8 +110,7 @@ def __init__( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None, row: Optional[int] = None, - ) -> None: - ... + ) -> None: ... def __init__( self, @@ -163,15 +161,13 @@ def user_select( disabled: bool = False, default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None, row: Optional[int] = None, -) -> Callable[[ItemCallbackType[V_co, UserSelect[V_co]]], DecoratedItem[UserSelect[V_co]]]: - ... +) -> Callable[[ItemCallbackType[V_co, UserSelect[V_co]]], DecoratedItem[UserSelect[V_co]]]: ... @overload def user_select( cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs -) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: - ... +) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ... def user_select( diff --git a/disnake/utils.py b/disnake/utils.py index a99b5558e4..d4d61a9579 100644 --- a/disnake/utils.py +++ b/disnake/utils.py @@ -145,12 +145,10 @@ def __init__(self, name: str, function: Callable[[T], T_co]) -> None: self.__doc__ = function.__doc__ @overload - def __get__(self, instance: None, owner: Type[Any]) -> Self: - ... + def __get__(self, instance: None, owner: Type[Any]) -> Self: ... @overload - def __get__(self, instance: T, owner: Type[Any]) -> T_co: - ... + def __get__(self, instance: T, owner: Type[Any]) -> T_co: ... def __get__(self, instance: Optional[T], owner: Type[Any]) -> Any: if instance is None: @@ -211,18 +209,15 @@ def count(self, value: Any) -> int: @overload -def parse_time(timestamp: None) -> None: - ... +def parse_time(timestamp: None) -> None: ... @overload -def parse_time(timestamp: str) -> datetime.datetime: - ... +def parse_time(timestamp: str) -> datetime.datetime: ... @overload -def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]: - ... +def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]: ... def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]: @@ -232,13 +227,11 @@ def parse_time(timestamp: Optional[str]) -> Optional[datetime.datetime]: @overload -def isoformat_utc(dt: datetime.datetime) -> str: - ... +def isoformat_utc(dt: datetime.datetime) -> str: ... @overload -def isoformat_utc(dt: Optional[datetime.datetime]) -> Optional[str]: - ... +def isoformat_utc(dt: Optional[datetime.datetime]) -> Optional[str]: ... def isoformat_utc(dt: Optional[datetime.datetime]) -> Optional[str]: @@ -514,7 +507,7 @@ def _maybe_cast(value: V, converter: Callable[[V], T], default: T = None) -> Opt def _get_mime_type_for_data(data: _BytesLike) -> str: - if data[0:8] == b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A": + if data[0:8] == b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a": return "image/png" elif data[0:3] == b"\xff\xd8\xff" or data[6:10] in (b"JFIF", b"Exif"): return "image/jpeg" @@ -548,13 +541,11 @@ def _get_extension_for_data(data: _BytesLike) -> Optional[str]: @overload -async def _assetbytes_to_base64_data(data: None) -> None: - ... +async def _assetbytes_to_base64_data(data: None) -> None: ... @overload -async def _assetbytes_to_base64_data(data: AssetBytes) -> str: - ... +async def _assetbytes_to_base64_data(data: AssetBytes) -> str: ... async def _assetbytes_to_base64_data(data: Optional[AssetBytes]) -> Optional[str]: @@ -695,8 +686,7 @@ class SnowflakeList(array.array): if TYPE_CHECKING: - def __init__(self, data: Iterable[int], *, is_sorted: bool = False) -> None: - ... + def __init__(self, data: Iterable[int], *, is_sorted: bool = False) -> None: ... def __new__(cls, data: Iterable[int], *, is_sorted: bool = False): return array.array.__new__(cls, "Q", data if is_sorted else sorted(data)) # type: ignore @@ -729,15 +719,13 @@ def _string_width(string: str, *, _IS_ASCII=_IS_ASCII) -> int: @overload -def resolve_invite(invite: Union[Invite, str], *, with_params: Literal[False] = False) -> str: - ... +def resolve_invite(invite: Union[Invite, str], *, with_params: Literal[False] = False) -> str: ... @overload def resolve_invite( invite: Union[Invite, str], *, with_params: Literal[True] -) -> Tuple[str, Dict[str, str]]: - ... +) -> Tuple[str, Dict[str, str]]: ... def resolve_invite( @@ -1089,13 +1077,11 @@ async def _achunk(iterator: AsyncIterator[T], max_size: int) -> AsyncIterator[Li @overload -def as_chunks(iterator: Iterator[T], max_size: int) -> Iterator[List[T]]: - ... +def as_chunks(iterator: Iterator[T], max_size: int) -> Iterator[List[T]]: ... @overload -def as_chunks(iterator: AsyncIterator[T], max_size: int) -> AsyncIterator[List[T]]: - ... +def as_chunks(iterator: AsyncIterator[T], max_size: int) -> AsyncIterator[List[T]]: ... def as_chunks(iterator: _Iter[T], max_size: int) -> _Iter[List[T]]: diff --git a/disnake/voice_client.py b/disnake/voice_client.py index e9469af670..94f7f079d6 100644 --- a/disnake/voice_client.py +++ b/disnake/voice_client.py @@ -14,6 +14,7 @@ - When that's all done, we receive opcode 4 from the vWS. - Finally we can transmit data to endpoint:port. """ + from __future__ import annotations import asyncio diff --git a/disnake/webhook/__init__.py b/disnake/webhook/__init__.py index 42e0a37918..76a465aab4 100644 --- a/disnake/webhook/__init__.py +++ b/disnake/webhook/__init__.py @@ -9,6 +9,7 @@ :license: MIT, see LICENSE for more details. """ + from . import async_, sync from .async_ import * from .sync import * diff --git a/disnake/webhook/async_.py b/disnake/webhook/async_.py index 98650f4bf1..c4b77e2c43 100644 --- a/disnake/webhook/async_.py +++ b/disnake/webhook/async_.py @@ -1507,8 +1507,7 @@ async def send( applied_tags: Sequence[Snowflake] = ..., wait: Literal[True], delete_after: float = ..., - ) -> WebhookMessage: - ... + ) -> WebhookMessage: ... @overload async def send( @@ -1534,8 +1533,7 @@ async def send( applied_tags: Sequence[Snowflake] = ..., wait: Literal[False] = ..., delete_after: float = ..., - ) -> None: - ... + ) -> None: ... async def send( self, diff --git a/disnake/webhook/sync.py b/disnake/webhook/sync.py index bd9779db43..b754f8abff 100644 --- a/disnake/webhook/sync.py +++ b/disnake/webhook/sync.py @@ -911,8 +911,7 @@ def send( thread_name: str = ..., applied_tags: Sequence[Snowflake] = ..., wait: Literal[True], - ) -> SyncWebhookMessage: - ... + ) -> SyncWebhookMessage: ... @overload def send( @@ -933,8 +932,7 @@ def send( thread_name: str = ..., applied_tags: Sequence[Snowflake] = ..., wait: Literal[False] = ..., - ) -> None: - ... + ) -> None: ... def send( self, diff --git a/disnake/widget.py b/disnake/widget.py index 4293985a36..b47e6daa80 100644 --- a/disnake/widget.py +++ b/disnake/widget.py @@ -325,7 +325,9 @@ def __init__(self, *, state: ConnectionState, data: WidgetPayload) -> None: elif connected_channel: connected_channel = WidgetChannel(id=connected_channel, name="", position=0) - self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel)) # type: ignore + self.members.append( + WidgetMember(state=self._state, data=member, connected_channel=connected_channel) # type: ignore + ) def __str__(self) -> str: return self.json_url diff --git a/docs/extensions/fulltoc.py b/docs/extensions/fulltoc.py index e35cd79514..944039b2ae 100644 --- a/docs/extensions/fulltoc.py +++ b/docs/extensions/fulltoc.py @@ -24,7 +24,7 @@ # Changes made: # - added typehinting -# - formatted with black +# - formatted with ruff # - refactored generated toc to suit project documentation structure from __future__ import annotations diff --git a/examples/interactions/autocomplete.py b/examples/interactions/autocomplete.py index 99b2448957..020313bdf5 100644 --- a/examples/interactions/autocomplete.py +++ b/examples/interactions/autocomplete.py @@ -31,8 +31,7 @@ async def autocomplete_langs(inter, string: str) -> List[str]: async def languages_1( inter: disnake.CommandInteraction, language: str = commands.Param(autocomplete=autocomplete_langs), -): - ... +): ... # Instead of using Param, you can also create autocomplete options @@ -43,8 +42,7 @@ async def languages_1( @bot.slash_command() -async def languages_2(inter: disnake.CommandInteraction, language: str): - ... +async def languages_2(inter: disnake.CommandInteraction, language: str): ... @languages_2.autocomplete("language") diff --git a/examples/interactions/converters.py b/examples/interactions/converters.py index 99c89821da..ffa67035eb 100644 --- a/examples/interactions/converters.py +++ b/examples/interactions/converters.py @@ -16,8 +16,7 @@ async def clean_command( inter: disnake.CommandInteraction[commands.Bot], text: str = commands.Param(converter=lambda inter, text: text.replace("@", "\\@")), -): - ... +): ... # Converters may also set the type of the option using annotations. @@ -31,8 +30,7 @@ def avatar_converter(inter: disnake.CommandInteraction, user: disnake.User) -> s async def command_with_avatar( inter: disnake.CommandInteraction, avatar: str = commands.Param(converter=avatar_converter), -): - ... +): ... # Converting to custom classes is also very easy using class methods. @@ -50,8 +48,7 @@ async def from_option(cls, inter: disnake.CommandInteraction, user: disnake.User async def command_with_clsmethod( inter: disnake.CommandInteraction, some: SomeCustomClass = commands.Param(converter=SomeCustomClass.from_option), -): - ... +): ... # An even better approach is to register a method as the class converter, @@ -72,8 +69,7 @@ async def convert(cls, inter: disnake.CommandInteraction, user: disnake.User): async def command_with_convmethod( inter: disnake.CommandInteraction, other: OtherCustomClass, -): - ... +): ... @bot.event diff --git a/examples/interactions/param.py b/examples/interactions/param.py index cd235f75e5..d7f7ee5c29 100644 --- a/examples/interactions/param.py +++ b/examples/interactions/param.py @@ -24,8 +24,7 @@ async def simple( inter: disnake.CommandInteraction, required: str, optional: int = 0, -): - ... +): ... # builtins are not the only types supported. @@ -37,8 +36,7 @@ async def other_types( user: disnake.User, emoji: disnake.Emoji, member_or_role: Union[disnake.Member, disnake.Role], -): - ... +): ... # Adding descriptions to the command itself and to its options is @@ -66,8 +64,7 @@ async def defaults( inter: disnake.CommandInteraction[commands.Bot], string: str = "this is a default value", user: disnake.User = commands.Param(lambda inter: inter.author), -): - ... +): ... # You may limit numbers to a certain range using `commands.Range`. @@ -96,8 +93,7 @@ async def ranges( # This results in the slash command using a string option, which will be # converted to an integer locally, allowing for a wider range of numbers. @bot.slash_command() -async def large(inter: disnake.CommandInteraction, largenumber: commands.LargeInt): - ... +async def large(inter: disnake.CommandInteraction, largenumber: commands.LargeInt): ... @bot.event diff --git a/pyproject.toml b/pyproject.toml index d3c3267537..ef1d612739 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ tools = [ "slotscheck~=0.16.4", "python-dotenv~=1.0.0", "check-manifest==0.49", - "ruff==0.8.0", + "ruff==0.9.3", ] changelog = [ "towncrier==23.6.0", @@ -81,7 +81,7 @@ changelog = [ codemod = [ # run codemods on the respository (mostly automated typing) "libcst~=1.1.0", - "black==23.9.1", + "ruff==0.9.3", "autotyping==23.2.0", ] typing = [ @@ -105,7 +105,6 @@ build = [ ] [tool.pdm.scripts] -black = { composite = ["lint black"], help = "Run black" } docs = { cmd = "nox -Rs docs --", help = "Build the documentation for development" } lint = { cmd = "nox -Rs lint --", help = "Check all files for linting errors" } pyright = { cmd = "nox -Rs pyright --", help = "Run pyright" } @@ -115,7 +114,6 @@ test = { cmd = "nox -Rs test --", help = "Run pytest" } # legacy tasks for those who still type `task` [tool.taskipy.tasks] -black = { cmd = "black", help = "Run black" } docs = { cmd = "docs", help = "Build the documentation for development" } lint = { cmd = "lint", help = "Check all files for linting errors" } pyright = { cmd = "pyright", help = "Run pyright" } @@ -125,9 +123,6 @@ test = { cmd = "test", help = "Run pytest" } [tool.taskipy.settings] runner = "pdm run" -[tool.black] -line-length = 100 - [tool.ruff] line-length = 100 target-version = "py38" diff --git a/tests/ext/commands/test_base_core.py b/tests/ext/commands/test_base_core.py index ac6b5ee93b..8008193b8c 100644 --- a/tests/ext/commands/test_base_core.py +++ b/tests/ext/commands/test_base_core.py @@ -28,18 +28,15 @@ class TestDefaultPermissions: def test_decorator(self, meta: DecoratorMeta) -> None: class Cog(commands.Cog): @meta.decorator(default_member_permissions=64) - async def cmd(self, _) -> None: - ... + async def cmd(self, _) -> None: ... @commands.default_member_permissions(64) @meta.decorator() - async def above(self, _) -> None: - ... + async def above(self, _) -> None: ... @meta.decorator() @commands.default_member_permissions(64) - async def below(self, _) -> None: - ... + async def below(self, _) -> None: ... for c in (Cog, Cog()): assert c.cmd.default_member_permissions == Permissions(64) @@ -53,8 +50,7 @@ def test_decorator_overwrite(self, meta: DecoratorMeta) -> None: class Cog(commands.Cog): @commands.default_member_permissions(32) @meta.decorator(default_member_permissions=64) - async def above(self, _) -> None: - ... + async def above(self, _) -> None: ... # putting the decorator below shouldn't fail, for now # FIXME: (this is a side effect of how command copying works, @@ -63,8 +59,7 @@ async def above(self, _) -> None: class Cog2(commands.Cog): @meta.decorator(default_member_permissions=64) @commands.default_member_permissions(32) - async def below(self, _) -> None: - ... + async def below(self, _) -> None: ... for c in (Cog2, Cog2()): assert c.below.default_member_permissions == Permissions(32) @@ -74,22 +69,18 @@ def test_attrs(self, meta: DecoratorMeta) -> None: class Cog(commands.Cog, **kwargs): @meta.decorator() - async def no_overwrite(self, _) -> None: - ... + async def no_overwrite(self, _) -> None: ... @meta.decorator(default_member_permissions=64) - async def overwrite(self, _) -> None: - ... + async def overwrite(self, _) -> None: ... @commands.default_member_permissions(64) @meta.decorator() - async def overwrite_decorator_above(self, _) -> None: - ... + async def overwrite_decorator_above(self, _) -> None: ... @meta.decorator() @commands.default_member_permissions(64) - async def overwrite_decorator_below(self, _) -> None: - ... + async def overwrite_decorator_below(self, _) -> None: ... assert Cog.no_overwrite.default_member_permissions is None assert Cog().no_overwrite.default_member_permissions == Permissions(32) @@ -112,8 +103,7 @@ class Cog(commands.Cog): @commands.install_types(user=True) # this is a legacy parameter, essentially the same as using `GuildCommandInteraction` @meta.decorator(guild_only=True) - async def cmd(self, _) -> None: - ... + async def cmd(self, _) -> None: ... for c in (Cog, Cog()): assert c.cmd.contexts == disnake.InteractionContextTypes(guild=True) @@ -129,8 +119,7 @@ def bot(self) -> commands.InteractionBot: def test_default(self, bot: commands.InteractionBot) -> None: @bot.slash_command() - async def c(inter) -> None: - ... + async def c(inter) -> None: ... assert c.body.to_dict().get("contexts") == [1] assert "dm_permission" not in c.body.to_dict() @@ -138,15 +127,13 @@ async def c(inter) -> None: def test_decorator_override(self, bot: commands.InteractionBot) -> None: @commands.contexts(private_channel=True) @bot.slash_command() - async def c(inter) -> None: - ... + async def c(inter) -> None: ... assert c.body.to_dict().get("contexts") == [2] def test_annotation_override(self, bot: commands.InteractionBot) -> None: @bot.slash_command() - async def c(inter: disnake.GuildCommandInteraction) -> None: - ... + async def c(inter: disnake.GuildCommandInteraction) -> None: ... assert c.body.to_dict().get("contexts") == [0] @@ -154,8 +141,7 @@ def test_dm_permission(self, bot: commands.InteractionBot) -> None: with warnings.catch_warnings(record=True): @bot.slash_command(dm_permission=False) - async def c(inter) -> None: - ... + async def c(inter) -> None: ... # if dm_permission was set, the `contexts` default shouldn't apply assert c.body.to_dict().get("contexts") is None @@ -169,8 +155,7 @@ async def cmd( self, inter, param: int = commands.Param(name=disnake.Localized("param", key="PARAM")), - ) -> None: - ... + ) -> None: ... # Ensure the command copy that happens on cog init doesn't raise a LocalizationWarning for the options. cog = Cog() diff --git a/tests/ext/commands/test_core.py b/tests/ext/commands/test_core.py index 2b29f51988..f98744d46c 100644 --- a/tests/ext/commands/test_core.py +++ b/tests/ext/commands/test_core.py @@ -6,12 +6,10 @@ from tests.helpers import reveal_type -class CustomContext(commands.Context): - ... +class CustomContext(commands.Context): ... -class CustomCog(commands.Cog): - ... +class CustomCog(commands.Cog): ... class TestDecorators: @@ -20,8 +18,7 @@ def _test_typing_defaults(self) -> None: # no cog - async def f1(ctx: CustomContext, a: int, b: str) -> bool: - ... + async def f1(ctx: CustomContext, a: int, b: str) -> bool: ... for cd in (commands.command(), base.command()): reveal_type( @@ -38,8 +35,7 @@ async def f1(ctx: CustomContext, a: int, b: str) -> bool: # custom cog base = commands.GroupMixin[CustomCog]() - async def f2(_self: CustomCog, ctx: CustomContext, a: int, b: str) -> bool: - ... + async def f2(_self: CustomCog, ctx: CustomContext, a: int, b: str) -> bool: ... for cd in (commands.command(), base.command()): reveal_type( @@ -54,19 +50,16 @@ async def f2(_self: CustomCog, ctx: CustomContext, a: int, b: str) -> bool: ) def _test_typing_cls(self) -> None: - class CustomCommand(commands.Command): - ... + class CustomCommand(commands.Command): ... - class CustomGroup(commands.Group): - ... + class CustomGroup(commands.Group): ... base = commands.GroupMixin[None]() command_decorators = (commands.command(cls=CustomCommand), base.command(cls=CustomCommand)) group_decorators = (commands.group(cls=CustomGroup), base.group(cls=CustomGroup)) - async def f(ctx: CustomContext, a: int, b: str) -> bool: - ... + async def f(ctx: CustomContext, a: int, b: str) -> bool: ... for cd in command_decorators: assert_type(cd(f), CustomCommand) diff --git a/tests/ext/commands/test_params.py b/tests/ext/commands/test_params.py index fdfaa59002..16af670df8 100644 --- a/tests/ext/commands/test_params.py +++ b/tests/ext/commands/test_params.py @@ -216,8 +216,7 @@ def test_optional(self, annotation_str) -> None: class TestIsolateSelf: def test_function_simple(self) -> None: - def func(a: int) -> None: - ... + def func(a: int) -> None: ... (cog, inter), params = commands.params.isolate_self(func) assert cog is None @@ -225,8 +224,7 @@ def func(a: int) -> None: assert params.keys() == {"a"} def test_function_inter(self) -> None: - def func(inter: disnake.ApplicationCommandInteraction, a: int) -> None: - ... + def func(inter: disnake.ApplicationCommandInteraction, a: int) -> None: ... (cog, inter), params = commands.params.isolate_self(func) assert cog is None # should not be set @@ -235,8 +233,7 @@ def func(inter: disnake.ApplicationCommandInteraction, a: int) -> None: def test_unbound_method(self) -> None: class Cog(commands.Cog): - def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: - ... + def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: ... (cog, inter), params = commands.params.isolate_self(Cog.func) assert cog is not None # *should* be set here @@ -246,8 +243,7 @@ def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: # I don't think the param parsing logic ever handles bound methods, but testing for regressions anyway def test_bound_method(self) -> None: class Cog(commands.Cog): - def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: - ... + def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: ... (cog, inter), params = commands.params.isolate_self(Cog().func) assert cog is None # should not be set here, since method is already bound @@ -255,8 +251,7 @@ def func(self, inter: disnake.ApplicationCommandInteraction, a: int) -> None: assert params.keys() == {"a"} def test_generic(self) -> None: - def func(inter: disnake.ApplicationCommandInteraction[commands.Bot], a: int) -> None: - ... + def func(inter: disnake.ApplicationCommandInteraction[commands.Bot], a: int) -> None: ... (cog, inter), params = commands.params.isolate_self(func) assert cog is None @@ -267,8 +262,7 @@ def test_inter_union(self) -> None: def func( inter: Union[commands.Context, disnake.ApplicationCommandInteraction[commands.Bot]], a: int, - ) -> None: - ... + ) -> None: ... (cog, inter), params = commands.params.isolate_self(func) assert cog is None diff --git a/tests/ext/commands/test_slash_core.py b/tests/ext/commands/test_slash_core.py index 498b706efc..7a296d73ad 100644 --- a/tests/ext/commands/test_slash_core.py +++ b/tests/ext/commands/test_slash_core.py @@ -8,20 +8,16 @@ class TestParents: def _create_cog(self): class Cog(commands.Cog): @commands.slash_command() - async def a(self, _) -> None: - ... + async def a(self, _) -> None: ... @a.sub_command() - async def sub(self, _) -> None: - ... + async def sub(self, _) -> None: ... @a.sub_command_group() - async def group(self, _) -> None: - ... + async def group(self, _) -> None: ... @group.sub_command() - async def subsub(self, _) -> None: - ... + async def subsub(self, _) -> None: ... return Cog() diff --git a/tests/ext/tasks/test_loops.py b/tests/ext/tasks/test_loops.py index 796b16f0c5..28a8dd54ed 100644 --- a/tests/ext/tasks/test_loops.py +++ b/tests/ext/tasks/test_loops.py @@ -13,8 +13,7 @@ class TestLoops: def test_decorator(self) -> None: class Cog(commands.Cog): @loop(seconds=30, minutes=0, hours=0) - async def task(self) -> None: - ... + async def task(self) -> None: ... for c in (Cog, Cog()): assert c.task.seconds == 30 @@ -22,8 +21,7 @@ async def task(self) -> None: with pytest.raises(TypeError, match="must be a coroutine"): @loop() # type: ignore - def task() -> None: - ... + def task() -> None: ... def test_mixing_time(self) -> None: async def callback() -> None: @@ -35,8 +33,7 @@ async def callback() -> None: with pytest.raises(TypeError): @loop(seconds=30, time=datetime.time()) - async def task() -> None: - ... + async def task() -> None: ... def test_inheritance(self) -> None: class HyperLoop(Loop[LF]): @@ -57,8 +54,7 @@ def clone(self): return instance class WhileTrueLoop: - def __init__(self, coro: Any) -> None: - ... + def __init__(self, coro: Any) -> None: ... async def callback() -> None: pass @@ -67,8 +63,7 @@ async def callback() -> None: class Cog(commands.Cog): @loop(cls=HyperLoop[Any], time_tup=(1, 2, 3)) - async def task(self) -> None: - ... + async def task(self) -> None: ... for c in (Cog, Cog()): assert (c.task.seconds, c.task.minutes, c.task.hours) == (1, 2, 3) @@ -76,5 +71,4 @@ async def task(self) -> None: with pytest.raises(TypeError, match="subclass of Loop"): @loop(cls=WhileTrueLoop) # type: ignore - async def task() -> None: - ... + async def task() -> None: ... diff --git a/tests/test_abc.py b/tests/test_abc.py index 844904630b..2fa1c0ceaf 100644 --- a/tests/test_abc.py +++ b/tests/test_abc.py @@ -156,8 +156,7 @@ async def test_overwrites(self, channel, sync_permissions) -> None: class TestUserProtocol: def _test_typing_assignable(self) -> None: - def handle_abc_user(user: disnake.abc.User) -> None: - ... + def handle_abc_user(user: disnake.abc.User) -> None: ... # All of these should match the abc.User protocol and thus type-check correctly # (they could just inherit from the protocol to ensure correct implementation, diff --git a/tests/test_events.py b/tests/test_events.py index 15cc467151..b9b0badea1 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -34,8 +34,7 @@ def test_event(client_or_bot: disnake.Client) -> None: assert not hasattr(client_or_bot, "on_message_edit") @client_or_bot.event - async def on_message_edit(self, *args: Any) -> None: - ... + async def on_message_edit(self, *args: Any) -> None: ... assert client_or_bot.on_message_edit is on_message_edit # type: ignore @@ -55,8 +54,7 @@ def test_wait_for(client_or_bot: disnake.Client, event) -> None: @pytest.mark.parametrize("event", ["on_guild_remove", Event.guild_remove]) def test_addremove_listener(client_or_bot: disnake.Client, event) -> None: - async def callback(self, *args: Any) -> None: - ... + async def callback(self, *args: Any) -> None: ... client_or_bot.add_listener(callback, event) assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 @@ -65,8 +63,7 @@ async def callback(self, *args: Any) -> None: def test_addremove_listener__implicit(client_or_bot: disnake.Client) -> None: - async def on_guild_remove(self, *args: Any) -> None: - ... + async def on_guild_remove(self, *args: Any) -> None: ... client_or_bot.add_listener(on_guild_remove) assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 @@ -80,16 +77,14 @@ async def on_guild_remove(self, *args: Any) -> None: @pytest.mark.parametrize("event", ["on_guild_role_create", Event.guild_role_create]) def test_listen(client_or_bot: disnake.Client, event) -> None: @client_or_bot.listen(event) - async def callback(self, *args: Any) -> None: - ... + async def callback(self, *args: Any) -> None: ... assert len(client_or_bot.extra_events["on_guild_role_create"]) == 1 def test_listen__implicit(client_or_bot: disnake.Client) -> None: @client_or_bot.listen() - async def on_guild_role_create(self, *args: Any) -> None: - ... + async def on_guild_role_create(self, *args: Any) -> None: ... assert len(client_or_bot.extra_events["on_guild_role_create"]) == 1 @@ -99,8 +94,7 @@ async def on_guild_role_create(self, *args: Any) -> None: def test_listener(bot: commands.Bot, event) -> None: class Cog(commands.Cog): @commands.Cog.listener(event) - async def callback(self, *args: Any) -> None: - ... + async def callback(self, *args: Any) -> None: ... bot.add_cog(Cog()) assert len(bot.extra_events["on_automod_rule_update"]) == 1 @@ -109,8 +103,7 @@ async def callback(self, *args: Any) -> None: def test_listener__implicit(bot: commands.Bot) -> None: class Cog(commands.Cog): @commands.Cog.listener() - async def on_automod_rule_update(self, *args: Any) -> None: - ... + async def on_automod_rule_update(self, *args: Any) -> None: ... bot.add_cog(Cog()) assert len(bot.extra_events["on_automod_rule_update"]) == 1 diff --git a/tests/test_utils.py b/tests/test_utils.py index ba4dca5e15..76a1bde329 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -73,8 +73,7 @@ def func(num: int, *, arg: str) -> float: ... @utils.copy_doc(func) - def func2(*args: Any, **kwargs: Any) -> Any: - ... + def func2(*args: Any, **kwargs: Any) -> Any: ... assert func2.__doc__ == func.__doc__ assert inspect.signature(func) == inspect.signature(func2) @@ -259,25 +258,25 @@ def test_maybe_cast() -> None: @pytest.mark.parametrize( ("data", "expected_mime", "expected_ext"), [ - (b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", "image/png", ".png"), - (b"\xFF\xD8\xFFxxxJFIF", "image/jpeg", ".jpg"), - (b"\xFF\xD8\xFFxxxExif", "image/jpeg", ".jpg"), - (b"\xFF\xD8\xFFxxxxxxxxxxxx", "image/jpeg", ".jpg"), + (b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", "image/png", ".png"), + (b"\xff\xd8\xffxxxJFIF", "image/jpeg", ".jpg"), + (b"\xff\xd8\xffxxxExif", "image/jpeg", ".jpg"), + (b"\xff\xd8\xffxxxxxxxxxxxx", "image/jpeg", ".jpg"), (b"xxxxxxJFIF", "image/jpeg", ".jpg"), (b"\x47\x49\x46\x38\x37\x61", "image/gif", ".gif"), (b"\x47\x49\x46\x38\x39\x61", "image/gif", ".gif"), (b"RIFFxxxxWEBP", "image/webp", ".webp"), (b"ID3", "audio/mpeg", ".mp3"), - (b"\xFF\xF3", "audio/mpeg", ".mp3"), + (b"\xff\xf3", "audio/mpeg", ".mp3"), (b"OggS", "audio/ogg", ".ogg"), ], ) def test_mime_type_valid(data, expected_mime, expected_ext) -> None: - for d in (data, data + b"\xFF"): + for d in (data, data + b"\xff"): assert utils._get_mime_type_for_data(d) == expected_mime assert utils._get_extension_for_data(d) == expected_ext - prefixed = b"\xFF" + data + prefixed = b"\xff" + data with pytest.raises(ValueError, match=r"Unsupported file type provided"): utils._get_mime_type_for_data(prefixed) assert utils._get_extension_for_data(prefixed) is None @@ -286,7 +285,7 @@ def test_mime_type_valid(data, expected_mime, expected_ext) -> None: @pytest.mark.parametrize( "data", [ - b"\x89\x50\x4E\x47\x0D\x0A\x1A\xFF", # invalid png end + b"\x89\x50\x4e\x47\x0d\x0a\x1a\xff", # invalid png end b"\x47\x49\x46\x38\x38\x61", # invalid gif version b"RIFFxxxxAAAA", b"AAAAxxxxWEBP", @@ -607,8 +606,7 @@ def test_escape_mentions(text: str, expected) -> None: ], ) def test_parse_docstring_desc(docstring: Optional[str], expected) -> None: - def f() -> None: - ... + def f() -> None: ... f.__doc__ = docstring assert utils.parse_docstring(f) == { @@ -667,8 +665,7 @@ def f() -> None: ], ) def test_parse_docstring_param(docstring: str, expected) -> None: - def f() -> None: - ... + def f() -> None: ... f.__doc__ = docstring expected = { @@ -970,8 +967,7 @@ def test_humanize_list(values, expected) -> None: # used for `test_signature_has_self_param` def _toplevel(): - def inner() -> None: - ... + def inner() -> None: ... return inner @@ -987,31 +983,26 @@ def wrap(self, *args, **kwargs): # used for `test_signature_has_self_param` class _Clazz: def func(self): - def inner() -> None: - ... + def inner() -> None: ... return inner @classmethod - def cmethod(cls) -> None: - ... + def cmethod(cls) -> None: ... @staticmethod - def smethod() -> None: - ... + def smethod() -> None: ... class Nested: def func(self): - def inner() -> None: - ... + def inner() -> None: ... return inner rebind = _toplevel @decorator - def decorated(self) -> None: - ... + def decorated(self) -> None: ... _lambda = lambda: None diff --git a/tests/ui/test_decorators.py b/tests/ui/test_decorators.py index 7dbe6aa488..c07c43dd05 100644 --- a/tests/ui/test_decorators.py +++ b/tests/ui/test_decorators.py @@ -31,8 +31,7 @@ def __init__(self, *, param: float = 42.0) -> None: pass -class _CustomView(ui.View): - ... +class _CustomView(ui.View): ... class TestDecorator: