Skip to content

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

Open
@llucax

Description

@llucax

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.

Activity

pawamoy

pawamoy commented on Nov 21, 2024

@pawamoy
Member

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

llucax

llucax commented on Nov 22, 2024

@llucax
Author

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

pawamoy commented on Nov 22, 2024

@pawamoy
Member

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 🙂

Kludex

Kludex commented on Dec 31, 2024

@Kludex

This would be very nice. I was going to ask about it.

samuelcolvin

samuelcolvin commented on Dec 31, 2024

@samuelcolvin

This would be great plase @pawamoy.

removed
fundIssue priority can be boosted
on Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @llucax@pawamoy@samuelcolvin@Kludex

      Issue actions

        feature: Convert `Unpack[TypedDict]` to regular arguments · Issue #207 · mkdocstrings/python