python / python/typing

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

オープン
#2,036 コメント 10 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic: feature
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず issue 内の wrapper と inner-function の例を確認し、次に既存の提案と制約について述べた、リンク先の mypy#19302 の議論を読んでください。*args と **kwargs を受け取る関数またはコンストラクターから wrapper の引数型を導出または宣言するための、文書化され合意されたアプローチができれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
32/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。