Skip to content

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open

Conversation

Soheab
Copy link
Contributor

@Soheab Soheab commented May 16, 2025

Summary

https://canary.discord.com/channels/336642139381301249/1371429669395759195

Tracking

  • discord
    • app_commands
      • checks.py
      • commands.py
      • errors.py
      • installs.py
      • models.py
      • namespace.py
      • transformers.py
      • translator.py
      • tree.py
    • ext
      • commands
        • bot.py
        • cog.py
        • context.py
        • converter.py
        • cooldowns.py
        • core.py
        • errors.py
        • flags.py
        • help.py
        • hybrid.py
        • parameters.py
        • view.py
      • tasks
        • init.py
    • ui
      • button.py
      • dynamic.py
      • items.py
      • modal.py
      • select.py
      • text_input.py
      • view.py
    • webhook
      • async_.py
      • sync.py
    • abc.py
    • activity.py
    • appinfo.py
    • asset.py
    • audit_logs.py
    • automod.py
    • backoff.py
    • channel.py
    • client.py
    • colour.py
    • components.py
    • context_managers.py
    • embeds.py
    • emoji.py
    • enums.py
    • errors.py
    • file.py
    • flags.py
    • gateway.py
    • guild.py
    • http.py
    • integrations.py
    • interactions.py
    • invite.py
    • member.py
    • mentions.py
    • message.py
    • mixins.py
    • object.py
    • oggparse.py
    • opus.py
    • partial_emoji.py
    • permissions.py
    • player.py
    • poll.py
    • presences.py
    • py.typed
    • raw_models.py
    • reaction.py
    • role.py
    • scheduled_event.py
    • shard.py
    • sku.py
    • soundboard.py
    • stage_instance.py
    • state.py
    • sticker.py
    • subscription.py
    • team.py
    • template.py
    • threads.py
    • user.py
    • utils.py
    • voice_client.py
    • voice_state.py
    • welcome_screen.py
    • widget.py

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@Soheab Soheab changed the title [WIP] Unpack usage where possible Unpack usage where possible May 16, 2025
@Soheab Soheab marked this pull request as ready for review May 17, 2025 20:12
Comment on lines +124 to +129
class _CreateChannelWithCategory(TypedDict, total=False):
category: Optional[CategoryChannel]

class _CreateNewsChannel(TypedDict, total=False):
news: bool

Copy link
Owner

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:
Copy link
Owner

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],
Copy link
Owner

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:
Copy link
Owner

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?

Copy link
Contributor Author

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:
Copy link
Owner

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:
Copy link
Owner

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:
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants