Browse Source

Use total=False over NotRequired everything

pull/10189/head
Soheab_ 1 week ago
parent
commit
b52ded68c8
  1. 42
      discord/client.py
  2. 12
      discord/ext/commands/bot.py
  3. 20
      discord/ext/commands/cog.py
  4. 54
      discord/ext/commands/core.py
  5. 46
      discord/ext/commands/help.py
  6. 46
      discord/ext/commands/hybrid.py
  7. 72
      discord/flags.py
  8. 230
      discord/permissions.py
  9. 8
      discord/shard.py

42
discord/client.py

@ -83,7 +83,7 @@ from .soundboard import SoundboardDefaultSound, SoundboardSound
if TYPE_CHECKING: if TYPE_CHECKING:
from types import TracebackType from types import TracebackType
from typing_extensions import Self, NotRequired, Unpack from typing_extensions import Self, Unpack
from .abc import Messageable, PrivateChannel, Snowflake, SnowflakeTime from .abc import Messageable, PrivateChannel, Snowflake, SnowflakeTime
from .app_commands import Command, ContextMenu from .app_commands import Command, ContextMenu
@ -123,26 +123,26 @@ if TYPE_CHECKING:
from .subscription import Subscription from .subscription import Subscription
from .flags import MemberCacheFlags from .flags import MemberCacheFlags
class _ClientOptions(TypedDict): class _ClientOptions(TypedDict, total=False):
max_messages: NotRequired[Optional[int]] max_messages: int
proxy: NotRequired[Optional[str]] proxy: str
proxy_auth: NotRequired[Optional[aiohttp.BasicAuth]] proxy_auth: aiohttp.BasicAuth
shard_id: NotRequired[Optional[int]] shard_id: int
shard_count: NotRequired[Optional[int]] shard_count: int
application_id: NotRequired[int] application_id: int
member_cache_flags: NotRequired[MemberCacheFlags] member_cache_flags: MemberCacheFlags
chunk_guilds_at_startup: NotRequired[bool] chunk_guilds_at_startup: bool
status: NotRequired[Optional[Status]] status: Status
activity: NotRequired[Optional[BaseActivity]] activity: BaseActivity
allowed_mentions: NotRequired[Optional[AllowedMentions]] allowed_mentions: AllowedMentions
heartbeat_timeout: NotRequired[float] heartbeat_timeout: float
guild_ready_timeout: NotRequired[float] guild_ready_timeout: float
assume_unsync_clock: NotRequired[bool] assume_unsync_clock: bool
enable_debug_events: NotRequired[bool] enable_debug_events: bool
enable_raw_presences: NotRequired[bool] enable_raw_presences: bool
http_trace: NotRequired[Optional[aiohttp.TraceConfig]] http_trace: aiohttp.TraceConfig
max_ratelimit_timeout: NotRequired[Optional[float]] max_ratelimit_timeout: float
connector: NotRequired[Optional[aiohttp.BaseConnector]] connector: aiohttp.BaseConnector
# fmt: off # fmt: off

12
discord/ext/commands/bot.py

@ -64,7 +64,7 @@ from .cog import Cog
from .hybrid import hybrid_command, hybrid_group, HybridCommand, HybridGroup from .hybrid import hybrid_command, hybrid_group, HybridCommand, HybridGroup
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack, NotRequired from typing_extensions import Self, Unpack
import importlib.machinery import importlib.machinery
@ -88,11 +88,11 @@ if TYPE_CHECKING:
_PrefixCallable = MaybeAwaitableFunc[[BotT, Message], _Prefix] _PrefixCallable = MaybeAwaitableFunc[[BotT, Message], _Prefix]
PrefixType = Union[_Prefix, _PrefixCallable[BotT]] PrefixType = Union[_Prefix, _PrefixCallable[BotT]]
class _BotOptions(_ClientOptions): class _BotOptions(_ClientOptions, total=False):
owner_id: NotRequired[Optional[int]] owner_id: int
owner_ids: NotRequired[Optional[Collection[int]]] owner_ids: Collection[int]
strip_after_prefix: NotRequired[bool] strip_after_prefix: bool
case_insensitive: NotRequired[bool] case_insensitive: bool
class _AutoShardedBotOptions(_AutoShardedClientOptions, _BotOptions): class _AutoShardedBotOptions(_AutoShardedClientOptions, _BotOptions):
... ...

20
discord/ext/commands/cog.py

@ -50,7 +50,7 @@ from typing import (
from ._types import _BaseCommand, BotT from ._types import _BaseCommand, BotT
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack, NotRequired from typing_extensions import Self, Unpack
from discord.abc import Snowflake from discord.abc import Snowflake
from discord._types import ClientT from discord._types import ClientT
@ -58,15 +58,15 @@ if TYPE_CHECKING:
from .context import Context from .context import Context
from .core import Command, _CommandDecoratorKwargs from .core import Command, _CommandDecoratorKwargs
class _CogKwargs(TypedDict): class _CogKwargs(TypedDict, total=False):
name: NotRequired[Optional[str]] name: str
group_name: NotRequired[Optional[Union[str, app_commands.locale_str]]] group_name: Union[str, app_commands.locale_str]
description: NotRequired[Optional[str]] description: str
group_description: NotRequired[Optional[Union[str, app_commands.locale_str]]] group_description: Union[str, app_commands.locale_str]
group_nsfw: NotRequired[bool] group_nsfw: bool
group_auto_locale_strings: NotRequired[bool] group_auto_locale_strings: bool
group_extras: NotRequired[Dict[Any, Any]] group_extras: Dict[Any, Any]
command_attrs: NotRequired[_CommandDecoratorKwargs] command_attrs: _CommandDecoratorKwargs
__all__ = ( __all__ = (

54
discord/ext/commands/core.py

@ -59,38 +59,38 @@ from .parameters import Parameter, Signature
from discord.app_commands.commands import NUMPY_DOCSTRING_ARG_REGEX from discord.app_commands.commands import NUMPY_DOCSTRING_ARG_REGEX
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Concatenate, ParamSpec, Self, NotRequired, Unpack from typing_extensions import Concatenate, ParamSpec, Self, Unpack
from ._types import BotT, Check, ContextT, Coro, CoroFunc, Error, Hook, UserCheck from ._types import BotT, Check, ContextT, Coro, CoroFunc, Error, Hook, UserCheck
from discord.permissions import _PermissionsKwargs from discord.permissions import _PermissionsKwargs
class _CommandDecoratorKwargs(TypedDict): class _CommandDecoratorKwargs(TypedDict, total=False):
enabled: NotRequired[bool] enabled: bool
help: NotRequired[str] help: str
brief: NotRequired[str] brief: str
usage: NotRequired[str] usage: str
rest_is_raw: NotRequired[bool] rest_is_raw: bool
aliases: NotRequired[List[str]] aliases: List[str]
description: NotRequired[str] description: str
hidden: NotRequired[bool] hidden: bool
checks: NotRequired[List[UserCheck[Context[Any]]]] checks: List[UserCheck[Context[Any]]]
cooldown: NotRequired[CooldownMapping[Context[Any]]] cooldown: CooldownMapping[Context[Any]]
max_concurrency: NotRequired[MaxConcurrency] max_concurrency: MaxConcurrency
require_var_positional: NotRequired[bool] require_var_positional: bool
cooldown_after_parsing: NotRequired[bool] cooldown_after_parsing: bool
ignore_extra: NotRequired[bool] ignore_extra: bool
extras: NotRequired[Dict[Any, Any]] extras: Dict[Any, Any]
class _CommandKwargs(_CommandDecoratorKwargs): class _CommandKwargs(_CommandDecoratorKwargs, total=False):
name: NotRequired[str] name: str
class _GroupDecoratorKwargs(_CommandDecoratorKwargs): class _GroupDecoratorKwargs(_CommandDecoratorKwargs, total=False):
invoke_without_command: NotRequired[bool] invoke_without_command: bool
case_insensitive: NotRequired[bool] case_insensitive: bool
class _GroupKwargs(_GroupDecoratorKwargs): class _GroupKwargs(_GroupDecoratorKwargs, total=False):
name: NotRequired[str] name: str
__all__ = ( __all__ = (

46
discord/ext/commands/help.py

@ -51,7 +51,7 @@ from .core import Group, Command, get_signature_parameters
from .errors import CommandError from .errors import CommandError
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack, NotRequired from typing_extensions import Self, Unpack
import discord.abc import discord.abc
@ -67,28 +67,28 @@ if TYPE_CHECKING:
_Bot, _Bot,
) )
class _HelpCommandOptions(TypedDict): class _HelpCommandOptions(TypedDict, total=False):
show_hidden: NotRequired[bool] show_hidden: bool
verify_checks: NotRequired[bool] verify_checks: bool
command_attrs: NotRequired[_CommandKwargs] command_attrs: _CommandKwargs
class _BaseHelpCommandOptions(_HelpCommandOptions): class _BaseHelpCommandOptions(_HelpCommandOptions, total=False):
sort_commands: NotRequired[bool] sort_commands: bool
dm_help: NotRequired[bool] dm_help: bool
dm_help_threshold: NotRequired[int] dm_help_threshold: int
no_category: NotRequired[str] no_category: str
paginator: NotRequired[Paginator] paginator: Paginator
commands_heading: NotRequired[str] commands_heading: str
class _DefaultHelpCommandOptions(_BaseHelpCommandOptions): class _DefaultHelpCommandOptions(_BaseHelpCommandOptions, total=False):
width: NotRequired[int] width: int
indent: NotRequired[int] indent: int
arguments_heading: NotRequired[str] arguments_heading: str
default_argument_description: NotRequired[str] default_argument_description: str
show_parameter_descriptions: NotRequired[bool] show_parameter_descriptions: bool
class _MinimalHelpCommandOptions(_BaseHelpCommandOptions): class _MinimalHelpCommandOptions(_BaseHelpCommandOptions, total=False):
aliases_heading: NotRequired[str] aliases_heading: str
__all__ = ( __all__ = (

46
discord/ext/commands/hybrid.py

@ -39,7 +39,7 @@ from .cog import Cog
from .view import StringView from .view import StringView
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, ParamSpec, Concatenate, Unpack, NotRequired from typing_extensions import Self, ParamSpec, Concatenate, Unpack
from ._types import ContextT, Coro, BotT from ._types import ContextT, Coro, BotT
from .bot import Bot from .bot import Bot
from .context import Context from .context import Context
@ -50,29 +50,27 @@ if TYPE_CHECKING:
) )
from .core import _CommandKwargs from .core import _CommandKwargs
class _HybridCommandKwargs( class _HybridCommandKwargs(_CommandKwargs, total=False):
_CommandKwargs, guild_ids: list[int]
): guild_only: bool
guild_ids: NotRequired[Optional[List[int]]] default_permissions: bool
guild_only: NotRequired[bool] nsfw: bool
default_permissions: NotRequired[Optional[bool]] with_app_command: bool
nsfw: NotRequired[bool]
with_app_command: NotRequired[bool] class _HybridCommandDecoratorKwargs(_HybridCommandKwargs, total=False):
description: Union[str, app_commands.locale_str]
class _HybridCommandDecoratorKwargs(_HybridCommandKwargs):
description: NotRequired[Union[str, app_commands.locale_str]] class _HybridGroupKwargs(_HybridCommandDecoratorKwargs, total=False):
with_app_command: bool
class _HybridGroupKwargs(_HybridCommandDecoratorKwargs): guild_ids: list[int]
with_app_command: NotRequired[bool] guild_only: bool
guild_ids: NotRequired[Optional[List[int]]] default_permissions: bool
guild_only: NotRequired[bool] nsfw: bool
default_permissions: NotRequired[Optional[bool]] description: str
nsfw: NotRequired[bool]
description: NotRequired[str] class _HybridGroupDecoratorKwargs(_HybridGroupKwargs, total=False):
description: Union[str, app_commands.locale_str]
class _HybridGroupDecoratorKwargs(_HybridGroupKwargs): fallback: Union[str, app_commands.locale_str]
description: NotRequired[Union[str, app_commands.locale_str]]
fallback: NotRequired[Union[str, app_commands.locale_str]]
__all__ = ( __all__ = (

72
discord/flags.py

@ -46,42 +46,42 @@ from typing import (
from .enums import UserFlags from .enums import UserFlags
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack, NotRequired from typing_extensions import Self, Unpack
class _IntentsFlagsKwargs(TypedDict): class _IntentsFlagsKwargs(TypedDict, total=False):
guilds: NotRequired[bool] guilds: bool
members: NotRequired[bool] members: bool
moderation: NotRequired[bool] moderation: bool
bans: NotRequired[bool] bans: bool
emojis: NotRequired[bool] emojis: bool
emojis_and_stickers: NotRequired[bool] emojis_and_stickers: bool
expressions: NotRequired[bool] expressions: bool
integrations: NotRequired[bool] integrations: bool
webhooks: NotRequired[bool] webhooks: bool
invites: NotRequired[bool] invites: bool
voice_states: NotRequired[bool] voice_states: bool
presences: NotRequired[bool] presences: bool
messages: NotRequired[bool] messages: bool
guild_messages: NotRequired[bool] guild_messages: bool
dm_messages: NotRequired[bool] dm_messages: bool
reactions: NotRequired[bool] reactions: bool
guild_reactions: NotRequired[bool] guild_reactions: bool
dm_reactions: NotRequired[bool] dm_reactions: bool
typing: NotRequired[bool] typing: bool
guild_typing: NotRequired[bool] guild_typing: bool
dm_typing: NotRequired[bool] dm_typing: bool
message_content: NotRequired[bool] message_content: bool
guild_scheduled_events: NotRequired[bool] guild_scheduled_events: bool
auto_moderation: NotRequired[bool] auto_moderation: bool
auto_moderation_configuration: NotRequired[bool] auto_moderation_configuration: bool
auto_moderation_execution: NotRequired[bool] auto_moderation_execution: bool
polls: NotRequired[bool] polls: bool
guild_polls: NotRequired[bool] guild_polls: bool
dm_polls: NotRequired[bool] dm_polls: bool
class _MemberCacheFlagsKwargs(TypedDict): class _MemberCacheFlagsKwargs(TypedDict, total=False):
voice: NotRequired[bool] voice: bool
joined: NotRequired[bool] joined: bool
__all__ = ( __all__ = (

230
discord/permissions.py

@ -33,121 +33,121 @@ __all__ = (
) )
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack, NotRequired from typing_extensions import Self, Unpack
class _PermissionsKwargs(TypedDict): class _PermissionsKwargs(TypedDict, total=False):
create_instant_invite: NotRequired[bool] create_instant_invite: bool
kick_members: NotRequired[bool] kick_members: bool
ban_members: NotRequired[bool] ban_members: bool
administrator: NotRequired[bool] administrator: bool
manage_channels: NotRequired[bool] manage_channels: bool
manage_guild: NotRequired[bool] manage_guild: bool
add_reactions: NotRequired[bool] add_reactions: bool
view_audit_log: NotRequired[bool] view_audit_log: bool
priority_speaker: NotRequired[bool] priority_speaker: bool
stream: NotRequired[bool] stream: bool
read_messages: NotRequired[bool] read_messages: bool
view_channel: NotRequired[bool] view_channel: bool
send_messages: NotRequired[bool] send_messages: bool
send_tts_messages: NotRequired[bool] send_tts_messages: bool
manage_messages: NotRequired[bool] manage_messages: bool
embed_links: NotRequired[bool] embed_links: bool
attach_files: NotRequired[bool] attach_files: bool
read_message_history: NotRequired[bool] read_message_history: bool
mention_everyone: NotRequired[bool] mention_everyone: bool
external_emojis: NotRequired[bool] external_emojis: bool
use_external_emojis: NotRequired[bool] use_external_emojis: bool
view_guild_insights: NotRequired[bool] view_guild_insights: bool
connect: NotRequired[bool] connect: bool
speak: NotRequired[bool] speak: bool
mute_members: NotRequired[bool] mute_members: bool
deafen_members: NotRequired[bool] deafen_members: bool
move_members: NotRequired[bool] move_members: bool
use_voice_activation: NotRequired[bool] use_voice_activation: bool
change_nickname: NotRequired[bool] change_nickname: bool
manage_nicknames: NotRequired[bool] manage_nicknames: bool
manage_roles: NotRequired[bool] manage_roles: bool
manage_permissions: NotRequired[bool] manage_permissions: bool
manage_webhooks: NotRequired[bool] manage_webhooks: bool
manage_expressions: NotRequired[bool] manage_expressions: bool
manage_emojis: NotRequired[bool] manage_emojis: bool
manage_emojis_and_stickers: NotRequired[bool] manage_emojis_and_stickers: bool
use_application_commands: NotRequired[bool] use_application_commands: bool
request_to_speak: NotRequired[bool] request_to_speak: bool
manage_events: NotRequired[bool] manage_events: bool
manage_threads: NotRequired[bool] manage_threads: bool
create_public_threads: NotRequired[bool] create_public_threads: bool
create_private_threads: NotRequired[bool] create_private_threads: bool
send_messages_in_threads: NotRequired[bool] send_messages_in_threads: bool
external_stickers: NotRequired[bool] external_stickers: bool
use_external_stickers: NotRequired[bool] use_external_stickers: bool
use_embedded_activities: NotRequired[bool] use_embedded_activities: bool
moderate_members: NotRequired[bool] moderate_members: bool
use_soundboard: NotRequired[bool] use_soundboard: bool
use_external_sounds: NotRequired[bool] use_external_sounds: bool
send_voice_messages: NotRequired[bool] send_voice_messages: bool
create_expressions: NotRequired[bool] create_expressions: bool
create_events: NotRequired[bool] create_events: bool
send_polls: NotRequired[bool] send_polls: bool
create_polls: NotRequired[bool] create_polls: bool
use_external_apps: NotRequired[bool] use_external_apps: bool
class _PermissionOverwriteKwargs(_PermissionsKwargs): class _PermissionOverwriteKwargs(_PermissionsKwargs, total=False):
create_instant_invite: NotRequired[Optional[bool]] create_instant_invite: Optional[bool]
kick_members: NotRequired[Optional[bool]] kick_members: Optional[bool]
ban_members: NotRequired[Optional[bool]] ban_members: Optional[bool]
administrator: NotRequired[Optional[bool]] administrator: Optional[bool]
manage_channels: NotRequired[Optional[bool]] manage_channels: Optional[bool]
manage_guild: NotRequired[Optional[bool]] manage_guild: Optional[bool]
add_reactions: NotRequired[Optional[bool]] add_reactions: Optional[bool]
view_audit_log: NotRequired[Optional[bool]] view_audit_log: Optional[bool]
priority_speaker: NotRequired[Optional[bool]] priority_speaker: Optional[bool]
stream: NotRequired[Optional[bool]] stream: Optional[bool]
read_messages: NotRequired[Optional[bool]] read_messages: Optional[bool]
view_channel: NotRequired[Optional[bool]] view_channel: Optional[bool]
send_messages: NotRequired[Optional[bool]] send_messages: Optional[bool]
send_tts_messages: NotRequired[Optional[bool]] send_tts_messages: Optional[bool]
manage_messages: NotRequired[Optional[bool]] manage_messages: Optional[bool]
embed_links: NotRequired[Optional[bool]] embed_links: Optional[bool]
attach_files: NotRequired[Optional[bool]] attach_files: Optional[bool]
read_message_history: NotRequired[Optional[bool]] read_message_history: Optional[bool]
mention_everyone: NotRequired[Optional[bool]] mention_everyone: Optional[bool]
external_emojis: NotRequired[Optional[bool]] external_emojis: Optional[bool]
use_external_emojis: NotRequired[Optional[bool]] use_external_emojis: Optional[bool]
view_guild_insights: NotRequired[Optional[bool]] view_guild_insights: Optional[bool]
connect: NotRequired[Optional[bool]] connect: Optional[bool]
speak: NotRequired[Optional[bool]] speak: Optional[bool]
mute_members: NotRequired[Optional[bool]] mute_members: Optional[bool]
deafen_members: NotRequired[Optional[bool]] deafen_members: Optional[bool]
move_members: NotRequired[Optional[bool]] move_members: Optional[bool]
use_voice_activation: NotRequired[Optional[bool]] use_voice_activation: Optional[bool]
change_nickname: NotRequired[Optional[bool]] change_nickname: Optional[bool]
manage_nicknames: NotRequired[Optional[bool]] manage_nicknames: Optional[bool]
manage_roles: NotRequired[Optional[bool]] manage_roles: Optional[bool]
manage_permissions: NotRequired[Optional[bool]] manage_permissions: Optional[bool]
manage_webhooks: NotRequired[Optional[bool]] manage_webhooks: Optional[bool]
manage_expressions: NotRequired[Optional[bool]] manage_expressions: Optional[bool]
manage_emojis: NotRequired[Optional[bool]] manage_emojis: Optional[bool]
manage_emojis_and_stickers: NotRequired[Optional[bool]] manage_emojis_and_stickers: Optional[bool]
use_application_commands: NotRequired[Optional[bool]] use_application_commands: Optional[bool]
request_to_speak: NotRequired[Optional[bool]] request_to_speak: Optional[bool]
manage_events: NotRequired[Optional[bool]] manage_events: Optional[bool]
manage_threads: NotRequired[Optional[bool]] manage_threads: Optional[bool]
create_public_threads: NotRequired[Optional[bool]] create_public_threads: Optional[bool]
create_private_threads: NotRequired[Optional[bool]] create_private_threads: Optional[bool]
send_messages_in_threads: NotRequired[Optional[bool]] send_messages_in_threads: Optional[bool]
external_stickers: NotRequired[Optional[bool]] external_stickers: Optional[bool]
use_external_stickers: NotRequired[Optional[bool]] use_external_stickers: Optional[bool]
use_embedded_activities: NotRequired[Optional[bool]] use_embedded_activities: Optional[bool]
moderate_members: NotRequired[Optional[bool]] moderate_members: Optional[bool]
use_soundboard: NotRequired[Optional[bool]] use_soundboard: Optional[bool]
use_external_sounds: NotRequired[Optional[bool]] use_external_sounds: Optional[bool]
send_voice_messages: NotRequired[Optional[bool]] send_voice_messages: Optional[bool]
create_expressions: NotRequired[Optional[bool]] create_expressions: Optional[bool]
create_events: NotRequired[Optional[bool]] create_events: Optional[bool]
send_polls: NotRequired[Optional[bool]] send_polls: Optional[bool]
create_polls: NotRequired[Optional[bool]] create_polls: Optional[bool]
use_external_apps: NotRequired[Optional[bool]] use_external_apps: Optional[bool]
# A permission alias works like a regular flag but is marked # A permission alias works like a regular flag but is marked

8
discord/shard.py

@ -47,16 +47,16 @@ from .enums import Status
from typing import TYPE_CHECKING, Any, Callable, Tuple, Type, Optional, List, Dict from typing import TYPE_CHECKING, Any, Callable, Tuple, Type, Optional, List, Dict
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Unpack, NotRequired from typing_extensions import Unpack
from .gateway import DiscordWebSocket from .gateway import DiscordWebSocket
from .activity import BaseActivity from .activity import BaseActivity
from .flags import Intents from .flags import Intents
from .types.gateway import SessionStartLimit from .types.gateway import SessionStartLimit
from .client import _ClientOptions from .client import _ClientOptions
class _AutoShardedClientOptions(_ClientOptions): class _AutoShardedClientOptions(_ClientOptions, total=False):
shard_ids: NotRequired[Optional[List[int]]] shard_ids: List[int]
shard_connect_timeout: NotRequired[Optional[float]] shard_connect_timeout: Optional[float]
__all__ = ( __all__ = (

Loading…
Cancel
Save