Skip to content
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

feature: Convert Unpack[TypedDict] to regular arguments #207

Open
llucax opened this issue Nov 21, 2024 · 3 comments
Open

feature: Convert Unpack[TypedDict] to regular arguments #207

llucax opened this issue Nov 21, 2024 · 3 comments
Assignees
Labels
feature New feature or request fund Issue priority can be boosted

Comments

@llucax
Copy link

llucax commented Nov 21, 2024

Is your feature request related to a problem? Please describe.

Not a problem, but when writing functions/classes with lots of options, and in particular when these options need to be forwarded down to a few levels, it is extremely convenient to use Unpack[TypeDict] as the type for keyword arguments and group all arguments in a class that can be reused.

For example:

from typing import TypedDict, Unpack

class Args(TypedDict):
    """Arguments for the add function"""

    a: int
    """The first number"""
    b: int
    """The second number"""

def add(**args: Unpack[Args]) -> int:
    """Add two numbers together.

    Args:
        **args: The arguments for the function.

    Returns:
        The sum of the two numbers.
    """
    return args["a"] + args["b"]

Renders as:

image

Describe the solution you'd like

It would be nice if it were rendered as regular arguments instead, like:

image

Describe alternatives you've considered

They are basically above.

Additional context

I know this might be tricky, specially considering cases using Args(TypeDict, total=False) or NotRequired as in this case some arguments could not be present at all, which is different from passing None for example. But maybe there is a low hanging fruit, and at least some limited support could be added.

Boost priority

  • Boost priority in our backlog through Polar.sh. Higher pledge, higher priority.
  • Minimum pledge by user/organization is $5, minimum amount for boost is $30.
  • View all issues with pledges.
  • We receive the funds once the issue is completed and confirmed by you.
  • Features with the insiders label are released to sponsors first, and tied to a funding goal.
Fund with Polar
@llucax llucax added the feature New feature or request label Nov 21, 2024
@pawamoy
Copy link
Member

pawamoy commented Nov 21, 2024

Thanks for the request @llucax! Related: mkdocstrings/griffe#284.

@pawamoy pawamoy added the fund Issue priority can be boosted label Nov 21, 2024
@llucax
Copy link
Author

llucax commented Nov 22, 2024

Oh, thanks for the reference, I completely missed it. I was actually in doubt if it had to be reported in griffe or not 🤷

@pawamoy
Copy link
Member

pawamoy commented Nov 22, 2024

No worries, it's not a duplicate. Support for Unpack must be implemented in Griffe, but here we also want an option to actually unpack the signature when rendering 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request fund Issue priority can be boosted
Projects
None yet
Development

No branches or pull requests

2 participants