Fix various TypeDicts for Unpack

This commit is contained in:
Soheab
2025-09-28 18:03:50 +02:00
committed by Rapptz
parent 8b2fb89ffa
commit 22e1d2592c
6 changed files with 28 additions and 37 deletions

View File

@@ -124,25 +124,25 @@ if TYPE_CHECKING:
from .flags import MemberCacheFlags from .flags import MemberCacheFlags
class _ClientOptions(TypedDict, total=False): class _ClientOptions(TypedDict, total=False):
max_messages: int max_messages: Optional[int]
proxy: str proxy: Optional[str]
proxy_auth: aiohttp.BasicAuth proxy_auth: Optional[aiohttp.BasicAuth]
shard_id: int shard_id: Optional[int]
shard_count: int shard_count: Optional[int]
application_id: int application_id: int
member_cache_flags: MemberCacheFlags member_cache_flags: MemberCacheFlags
chunk_guilds_at_startup: bool chunk_guilds_at_startup: bool
status: Status status: Optional[Status]
activity: BaseActivity activity: Optional[BaseActivity]
allowed_mentions: AllowedMentions allowed_mentions: Optional[AllowedMentions]
heartbeat_timeout: float heartbeat_timeout: float
guild_ready_timeout: float guild_ready_timeout: float
assume_unsync_clock: bool assume_unsync_clock: bool
enable_debug_events: bool enable_debug_events: bool
enable_raw_presences: bool enable_raw_presences: bool
http_trace: aiohttp.TraceConfig http_trace: aiohttp.TraceConfig
max_ratelimit_timeout: float max_ratelimit_timeout: Optional[float]
connector: aiohttp.BaseConnector connector: Optional[aiohttp.BaseConnector]
# fmt: off # fmt: off

View File

@@ -89,8 +89,8 @@ if TYPE_CHECKING:
PrefixType = Union[_Prefix, _PrefixCallable[BotT]] PrefixType = Union[_Prefix, _PrefixCallable[BotT]]
class _BotOptions(_ClientOptions, total=False): class _BotOptions(_ClientOptions, total=False):
owner_id: int owner_id: Optional[int]
owner_ids: Collection[int] owner_ids: Optional[Collection[int]]
strip_after_prefix: bool strip_after_prefix: bool
case_insensitive: bool case_insensitive: bool

View File

@@ -45,29 +45,18 @@ from typing import (
Tuple, Tuple,
TypeVar, TypeVar,
Union, Union,
TypedDict,
) )
from ._types import _BaseCommand, BotT from ._types import _BaseCommand, BotT
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self, Unpack from typing_extensions import Self
from discord.abc import Snowflake from discord.abc import Snowflake
from discord._types import ClientT from discord._types import ClientT
from .bot import BotBase from .bot import BotBase
from .context import Context from .context import Context
from .core import Command, _CommandDecoratorKwargs from .core import Command
class _CogKwargs(TypedDict, total=False):
name: str
group_name: Union[str, app_commands.locale_str]
description: str
group_description: Union[str, app_commands.locale_str]
group_nsfw: bool
group_auto_locale_strings: bool
group_extras: Dict[Any, Any]
command_attrs: _CommandDecoratorKwargs
__all__ = ( __all__ = (
@@ -182,7 +171,7 @@ class CogMeta(type):
__cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]] __cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]]
__cog_listeners__: List[Tuple[str, str]] __cog_listeners__: List[Tuple[str, str]]
def __new__(cls, *args: Any, **kwargs: Unpack[_CogKwargs]) -> CogMeta: def __new__(cls, *args: Any, **kwargs: Any) -> CogMeta:
name, bases, attrs = args name, bases, attrs = args
if any(issubclass(base, app_commands.Group) for base in bases): if any(issubclass(base, app_commands.Group) for base in bases):
raise TypeError( raise TypeError(

View File

@@ -68,11 +68,11 @@ if TYPE_CHECKING:
class _CommandDecoratorKwargs(TypedDict, total=False): class _CommandDecoratorKwargs(TypedDict, total=False):
enabled: bool enabled: bool
help: str help: Optional[str]
brief: str brief: Optional[str]
usage: str usage: Optional[str]
rest_is_raw: bool rest_is_raw: bool
aliases: List[str] aliases: Union[List[str], Tuple[str, ...]]
description: str description: str
hidden: bool hidden: bool
checks: List[UserCheck[Context[Any]]] checks: List[UserCheck[Context[Any]]]
@@ -449,7 +449,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
self.brief: Optional[str] = kwargs.get('brief') self.brief: Optional[str] = kwargs.get('brief')
self.usage: Optional[str] = kwargs.get('usage') self.usage: Optional[str] = kwargs.get('usage')
self.rest_is_raw: bool = kwargs.get('rest_is_raw', False) self.rest_is_raw: bool = kwargs.get('rest_is_raw', False)
self.aliases: Union[List[str], Tuple[str]] = kwargs.get('aliases', []) self.aliases: Union[List[str], Tuple[str, ...]] = kwargs.get('aliases', [])
self.extras: Dict[Any, Any] = kwargs.get('extras', {}) self.extras: Dict[Any, Any] = kwargs.get('extras', {})
if not isinstance(self.aliases, (list, tuple)): if not isinstance(self.aliases, (list, tuple)):

View File

@@ -69,12 +69,12 @@ if TYPE_CHECKING:
class _HelpCommandOptions(TypedDict, total=False): class _HelpCommandOptions(TypedDict, total=False):
show_hidden: bool show_hidden: bool
verify_checks: bool verify_checks: Optional[bool]
command_attrs: _CommandKwargs command_attrs: _CommandKwargs
class _BaseHelpCommandOptions(_HelpCommandOptions, total=False): class _BaseHelpCommandOptions(_HelpCommandOptions, total=False):
sort_commands: bool sort_commands: bool
dm_help: bool dm_help: Optional[bool]
dm_help_threshold: int dm_help_threshold: int
no_category: str no_category: str
paginator: Paginator paginator: Paginator
@@ -394,7 +394,7 @@ class HelpCommand:
def __init__(self, **options: Unpack[_HelpCommandOptions]) -> None: def __init__(self, **options: Unpack[_HelpCommandOptions]) -> None:
self.show_hidden: bool = options.pop('show_hidden', False) self.show_hidden: bool = options.pop('show_hidden', False)
self.verify_checks: bool = options.pop('verify_checks', True) self.verify_checks: Optional[bool] = options.pop('verify_checks', True)
self.command_attrs = attrs = options.pop('command_attrs', {}) self.command_attrs = attrs = options.pop('command_attrs', {})
attrs.setdefault('name', 'help') attrs.setdefault('name', 'help')
attrs.setdefault('help', 'Shows this message') attrs.setdefault('help', 'Shows this message')
@@ -1070,7 +1070,7 @@ class DefaultHelpCommand(HelpCommand):
self.width: int = options.pop('width', 80) self.width: int = options.pop('width', 80)
self.indent: int = options.pop('indent', 2) self.indent: int = options.pop('indent', 2)
self.sort_commands: bool = options.pop('sort_commands', True) self.sort_commands: bool = options.pop('sort_commands', True)
self.dm_help: bool = options.pop('dm_help', False) self.dm_help: Optional[bool] = options.pop('dm_help', False)
self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000) self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000)
self.arguments_heading: str = options.pop('arguments_heading', 'Arguments:') self.arguments_heading: str = options.pop('arguments_heading', 'Arguments:')
self.commands_heading: str = options.pop('commands_heading', 'Commands:') self.commands_heading: str = options.pop('commands_heading', 'Commands:')
@@ -1364,7 +1364,7 @@ class MinimalHelpCommand(HelpCommand):
def __init__(self, **options: Unpack[_MinimalHelpCommandOptions]) -> None: def __init__(self, **options: Unpack[_MinimalHelpCommandOptions]) -> None:
self.sort_commands: bool = options.pop('sort_commands', True) self.sort_commands: bool = options.pop('sort_commands', True)
self.commands_heading: str = options.pop('commands_heading', 'Commands') self.commands_heading: str = options.pop('commands_heading', 'Commands')
self.dm_help: bool = options.pop('dm_help', False) self.dm_help: Optional[bool] = options.pop('dm_help', False)
self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000) self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000)
self.aliases_heading: str = options.pop('aliases_heading', 'Aliases:') self.aliases_heading: str = options.pop('aliases_heading', 'Aliases:')
self.no_category: str = options.pop('no_category', 'No Category') self.no_category: str = options.pop('no_category', 'No Category')

View File

@@ -67,10 +67,12 @@ if TYPE_CHECKING:
default_permissions: bool default_permissions: bool
nsfw: bool nsfw: bool
description: str description: str
case_insensitive: bool
class _HybridGroupDecoratorKwargs(_HybridGroupKwargs, total=False): class _HybridGroupDecoratorKwargs(_HybridGroupKwargs, total=False):
description: Union[str, app_commands.locale_str] description: Union[str, app_commands.locale_str]
fallback: Union[str, app_commands.locale_str] fallback: Optional[str]
fallback_locale: Optional[app_commands.locale_str]
__all__ = ( __all__ = (