Skip to content

Annotate *args/**kwargs based on the signature of another class/function #17119

Closed
@karb94

Description

@karb94

Feature

It is a common pattern to inherit a Parent class and call its __init__() using *args and **kwargs as below.

class Parent:
    def __init__(self, a: str, b: int = 0):
        print(a, b)

class Child(Parent):
    def __init__(self, c: float, *args, **kwargs):
        super().__init__(*args, **kwargs)
        print(c)

Is there a way of annotating the above *args and **kwargs without rewriting Parent's signature (i.e. no TypedDict + Unpack)?

I would find the following UX very convenient:

class Parent:
    def __init__(self, a: str, b: int = 0):
        print(a, b)

class Child(Parent):
    def __init__(self, c: float, *args: Parent.args, **kwargs: Parent.kwargs):
        super().__init__(*args: Parent.args, **kwargs: Parent.kwargs)
        print(c)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions