python / python/typing

Type checking for *args and **kwargs when passing them to another function

Open
#2,036 10 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: feature
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

Problem:

I am writing a python application, and I made a function that creates an object and passes its additional *args and **kwargs to object's constructor and takes few its own arguments. I want to make *args and **kwargs typed exactly as inner function's arguments.

Description and examples:

A simple example with two functions:

def inner(a: int, b: int) -> None:
    ...


def wrapper(arg1: str, *args, **kwargs) -> None:
    inner(*args, **kwargs)  # It will automatically detect passing arguments to another function

In my case, inner is object constructor, I gave an example with functions to make it more simple.

Type checkers should see wrapper's signature like this:

def wrapper(arg1: str, a: int, b: int):
    ...

It may be enabled by default when passing *args and **kwargs to another function is detected or it may be enabled by adding a decorator to the function.

Detailed description:

Already suggested this to mypy, detailed description of this feature can be found here: python/mypy#19302.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the wrapper and inner-function examples in the issue, then read the linked mypy#19302 discussion for the existing proposal and constraints. Done should be a documented, agreed approach for deriving or declaring wrapper argument types from the function or constructor receiving *args and **kwargs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.