-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Unpack usage where possible #10189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Unpack usage where possible #10189
Conversation
class _CreateChannelWithCategory(TypedDict, total=False): | ||
category: Optional[CategoryChannel] | ||
|
||
class _CreateNewsChannel(TypedDict, total=False): | ||
news: bool | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These appear unused.
@@ -272,7 +295,7 @@ class Client: | |||
The websocket gateway the client is currently connected to. Could be ``None``. | |||
""" | |||
|
|||
def __init__(self, *, intents: Intents, **options: Any) -> None: | |||
def __init__(self, *, intents: Intents, **options: Unpack[_ClientOptions]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the reason why I didn't do this before for Client
is because as part of the contract that you can inherit from Client
this means that any extra args would cause type errors even though they might use the extra kwargs themselves.
I'm unsure where I really stand on this from a usability POV, and I don't know if it's that annoying.
allowed_contexts: app_commands.AppCommandContext = MISSING, | ||
allowed_installs: app_commands.AppInstallationType = MISSING, | ||
intents: discord.Intents, | ||
**kwargs: Unpack[_AutoShardedBotOptions], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same nit as before.
@@ -169,7 +181,7 @@ async def bar(self, ctx): | |||
__cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]] | |||
__cog_listeners__: List[Tuple[str, str]] | |||
|
|||
def __new__(cls, *args: Any, **kwargs: Any) -> CogMeta: | |||
def __new__(cls, *args: Any, **kwargs: Unpack[_CogKwargs]) -> CogMeta: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this even work from a user's POV?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not. It does error out when the user has typed the correct name but the wrong type.
|
||
def __new__(cls, *args: Any, **kwargs: Any) -> Self: | ||
def __new__(cls, *args: Any, **kwargs: Unpack[_CommandKwargs]) -> Self: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is internal there's no need to type it.
@@ -754,12 +790,12 @@ class Intents(BaseFlags): | |||
|
|||
__slots__ = () | |||
|
|||
def __init__(self, value: int = 0, **kwargs: bool) -> None: | |||
def __init__(self, value: int = 0, **kwargs: Unpack[_IntentsFlagsKwargs]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another reason why I was not a fan of doing this is because now there are more places to edit when adding a single thing. This is especially egregious with permissions which need to have an added value both in its TYPE_CHECKING
block and now in its Unpack
dictionary.
I suppose it's unavoidable, but honestly it's just really annoying.
@@ -365,7 +371,7 @@ class AutoShardedClient(Client): | |||
if TYPE_CHECKING: | |||
_connection: AutoShardedConnectionState | |||
|
|||
def __init__(self, *args: Any, intents: Intents, **kwargs: Any) -> None: | |||
def __init__(self, *args: Any, intents: Intents, **kwargs: Unpack[_AutoShardedClientOptions]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same nit as Client
and AutoShardedBot
.
Summary
https://canary.discord.com/channels/336642139381301249/1371429669395759195
Tracking
Checklist